VC++ Unmanaged DLL in C#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sganeshcse
    New Member
    • Aug 2007
    • 6

    VC++ Unmanaged DLL in C#.net

    Hi All..

    I have a VC++ unmanaged dll in the shared drive. I have to call that one in to my C# application which is residing on my local hard drive.

    Clients restrictions are below

    1) We should not register Vc++ dll on the local machine
    2) We should not have the local copy of the dll

    I am struck on this for last 5 days...I am not able to find the solution....

    Please someone help me on this scenario....
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    As far as i know you need to register the dll using Regsvr32
    ... then add reference or add com reference.... i have limited knowledge in this area .. so may be there are other ways ...

    Comment

    • vekipeki
      Recognized Expert New Member
      • Nov 2007
      • 229

      #3
      Is it a COM object, or simply a native .dll? Why can't you P/Invoke it using DllImport?

      Comment

      • sganeshcse
        New Member
        • Aug 2007
        • 6

        #4
        It is not a COM dll. Is DLLImport is a runtime invocation method?

        Comment

        • vekipeki
          Recognized Expert New Member
          • Nov 2007
          • 229

          #5
          Good point... I don't think you can change the DllImport path during runtime. I wonder if it could be done through some Reflection (or Reflection.Emit )?

          Anyway, a general way would be to P/Invoke Kernel32.LoadLi braryW:

          Code:
          // using System.Runtime.InteropServices;
          [DllImport("kernel32.dll", EntryPoint = "LoadLibraryW")]
          static extern IntPtr LoadLibraryW([In][MarshalAs(UnmanagedType.LPWStr)] string lpLibFileName);
          and then use Kernel32.GetPro cAddress to get the function pointer to your native function.

          I Googled for ".NET Kernel32 GetProcAddress" and this came up: http://blogs.msdn.com/jmstall/archiv...ocAddress.aspx

          Comment

          Working...