Menu

Using a C++ class from a DLL

Thorn
2008-07-23
2012-09-26
  • Thorn

    Thorn - 2008-07-23

    I've been given an API that is in a DLL file. The documentation tells me that there is one class with several public variables and functions that can be used. How do I create an object from that class, given that I have not been provided with a LIB file?

    Thanks

     
    • Anonymous

      Anonymous - 2008-07-23

      IF the DLL has been constructed with the same Dev-C++ toolchain (GNU) then you don't need a .lib file. Otherwise you need at least a .def file.

       
    • Thorn

      Thorn - 2008-07-23

      Nope. All I have is the DLL file and some documentation that tell me the function and variable names.

       
    • Anonymous

      Anonymous - 2008-07-23

      A .DEF file is a plain text file, so You can write it with a text editor if you know the name of the exported functions.

      Here you have the aspect of one of those .DEF files (the very beginning of the .DEF file of sqlite3.dll, the popular RDBM engine):

      LIBRARY SQLITE3.DLL

      EXPORTS
      sqlite3_aggregate_context
      sqlite3_aggregate_count
      sqlite3_apis
      sqlite3_auto_extension
      sqlite3_bind_blob
      sqlite3_bind_double
      sqlite3_bind_int
      sqlite3_bind_int64
      sqlite3_bind_null
      ...

      You can write your own .DEF based in the documentation you have. After that, you can build your .LIB. IIRC the process has been explained in this forum already.

       
    • cpns

      cpns - 2008-07-23

      If the DLL contains C++ code without C linkage (and classes for example cannot have C linkage in any case) then you are probably out of luck unless it happened to have been compiled with MinGW/GCC 3.x.

      There is no standard for C++ name-mangling (the technique used to support member function and variables, and also function overloading), so the object code you generate with Dev-C++ will not contain names that match up with those in the library.

      You can load and access a DLL porgramatically using LoadLibrary() and GetProcAddress(), but you will still need to know the manggled symbol names.

      You at least have a header file too right? Or at least enough documentation to be able to generate one?

      Surely the path of least resistance if (as is likely this is a MSVC++ generated library) is to use http://www.microsoft.com/express/vc/

      Clifford

       
    • Anonymous

      Anonymous - 2008-07-23

      I forgot to mention that the IMPDEF.EXE program that comes with the Borland compiler takes a DLL and creates a module definition file (.DEF). At this moment I don't remember if the "binutils" of the GNU tool chain has a similar utility.

      Athough a bit off-topic, if you want use the MS tool chain (Visual C++), look up the "Article ID: Q131313" http://support.microsoft.com/kb/q131313/, it shows how to create the import library given just a DLL. It is a multi-step process that is verbose compared to other compilers.

      HTH

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.