my asp.net app to call dll

Discussion in 'ASP.NET / ASP.NET Core' started by tomdickorharry, Jul 23, 2010.

  1. Hi

    I would like to be able to call a non-com, true windows 32 dll from my asp.net 3.5 app, that's to be located, say in my bin folder e.g.

    \bin\no_i_do_not_need_registration.dll

    I have already asked support twice for help re this under ticket 035-13DBFBC6-263, but they now advise me I need to post my support request here in the public forum.

    I do not want to go into specific details here in a public forum, so can please
    can you look at the above ticket for details. (And you will understand why!)

    Any one here want to help me please?

    Thanks and regards,

    tomdickorharry
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    this is a public forum and most do not have access to the ticket. I think you should post your question with details for us to help you.
     
  3. Any using a non-com, true windows native dll from there web app.
    Is there any special setup for this e.g. does it have to be put in the server's
    Path so the web app can find and call it?
     
  4. Are you writing your own client code to call this DLL? If so, you should be able to put the DLL file in the bin folder and call it from there. I don't believe there are any restrictions using the System.Runtime.InteropServices.DllImport attribute on the web server (DASP support should actually be able to tell you this) so as far as I'm aware you should be able to do this:

    [DllImport("Kernel32.dll", CharSet=CharSet.Unicode)]
    static int LoadLibrary(string DLLPath);
    [DllImport("Kernel32.dll", CharSet=CharSet.Unicode)]
    static int FreeLibrary(int Handle);

    ..and you'll need to declare all of the methods in the DLL you need to call too.

    I haven't actually done it myself but it wouldn't be a big task to develop a little test application for the DASP web server to prove whether this works or not.

    If you're relying on some 3rd party code in your web application to call this thing, it might have special requirements where this DLL should be located.
     
  5. Hi CrystalCMS

    My web app is calling a console app, that's in turn is calling the dll,
    with the web app capturing stdout from the console app.

    Unfortunately it's not working at DASP. I'm adding a log table
    to my db right now so each component in the process can log to that
    so I can what is/is not happening.

    If I get anything worth sharing/asking, I'll post again here.

    Thanks for your help,

    Martyn THE tomdickorharry
     
  6. Ah that's sounds like a different scenario to your original question. If your web application is referencing and trying to use the output from a console application, this means your w3wp IIS worker process on the server will be attempting to spawn another process and the console app would have it's own .NET application domain. I expect there are measures to prevent this type of application behaviour on the web server. If you do have this working locally in your dev environment, you probably see the console application window appear as a new O/S window when the your web application uses it and I can't imagine this would be allowed on a DASP web server.

    Your best bet will be to attempt to use the DLL directly from your web application code; I think this stands the best chance of working because this is an in-process operation.
     
  7. I could not get a direct call from the webapp to the dll workingm, using [DllImport etc. Its the softwarepassport's codegen.dll to generate trial keys for my vb6 shareware app.

    On my dev machine, I could get the console to call the dll and pass the key back, via stdoutput, so my use of the console, was just a workaround
    for not getting webapp to call the dll directly.

    BTW I'm using the code here by SeemabK
    at the bottom of Hanselmans site:
    http://www.hanselman.com/blog/SoMan...ecapturingStandardErrorAndStandardOutput.aspx to avoid stdout/stderror
    blocking each other.

    I was reading the console's stdoutput to be more 'professional' but could easily write the key to a text file and have the web app read that.

    It would be useful to know if anyone has got a .net console app to run sucessfully here, and also if DASP support can confirm if it is possible to spawn and run a .net console or not, because if not, I will have to go back to hitting my head against the wall with that DllImport cr*p...

    Martyn
     

Share This Page