none
Problem in accessing a class in dll

    Question

  •  

    I have a Third Party dll (MarkLogicXdmp.dll)

     

    I want to use that dll in VC++ win32 Project.

     

    I am able to load the dll into VC++ form application and console application, using static linking and the code that I am working looks like this:

     

     

    XdmpConnection ^conn = gcnew XdmpConnection("localhost", 8090);

     

    Conn->SetCredentials ("mark", "mark");

     

     

    Where XdmpConnection is a class in that dll (MarkLogicXdmp.dll) and SetCredentials is a function in that class.

     

    Now I want to implement this code in “VC++ win32 Project”. Here we can’t load a dll statically. So, I tried to load the dll using LoadLibrary () function (Dynamic loading) and got succeeded, But don’t know how to instantiate the class in that dll.

     

    Can any one help in doing this?

     

    Thanks in Advance for your response..

     

     

    Friday, August 17, 2007 7:16 AM

Answers

  • You can't load a managed assembly via LoadLibrary or via the import table (well you can, it just doesn't make sense).

     

    If you want to access managed functionality, you have a couple of options depending on your requirements and the interface of the third-party DLL. The easiest way would be to use the same method as in your Forms App. You just need to enable managed code extensions for some of your application. There should be plenty of examples available on to how to extend an existing native application with managed code.

     

    -hg

     

    Monday, August 20, 2007 8:49 AM

All replies

  • Hi,

     

    Couple things.  There are basically two ways to load a DLL under Win32:

     

    a) Implicitly, by using the DLL's import library (.LIB file).  This happens at link-time.

    b) Explicitly, by using the LoadLibrary() API followed by GetProcAddress().  This happens at run-time.

     

    You use the phrase "static linking" which really implies something a little different.

     

    If you want to access a class, and member functions within that class, I suggest you use method A.  In general, use method A unless you've got a definite reason to use method B.

     

    To do this:

     

    First include the header file(s) for the class you want to use.  Instantiate and use the class just like you would any other class.  Get everything compiling cleanly.  Then during the link phase you'll get an error.

     

    At this point, take the .LIB file which ships (or should ship) with MarkLogicXdmp.dll and specify it as an input in your linker settings.  This can be found under Project Settings -> Linker -> Input.

     

     

    Friday, August 17, 2007 2:35 PM
  • Hi,

     

    Thanks for your response.

     

    The dll that Im using (MarkLogicXdmp.dll) is a third party dll.

    And, I dont have .LIB file or .H (header file) of that dll (MarkLogicXdmp.dll).

     

    So I cant use your method (Method A).

    Please give any suggestion to proceed using LoadLIbrary() API.

     

     

    Monday, August 20, 2007 4:57 AM
  • You can't load a managed assembly via LoadLibrary or via the import table (well you can, it just doesn't make sense).

     

    If you want to access managed functionality, you have a couple of options depending on your requirements and the interface of the third-party DLL. The easiest way would be to use the same method as in your Forms App. You just need to enable managed code extensions for some of your application. There should be plenty of examples available on to how to extend an existing native application with managed code.

     

    -hg

     

    Monday, August 20, 2007 8:49 AM
  • Yes, what Holger said!  I was under the impression that the third-party DLL you were trying to use was a native/unmanaged DLL.

    Monday, August 20, 2007 2:35 PM