How to use a DLL without the need of its .h and .l

2019-06-24 03:09发布

问题:

I don't know how to do the following:

  • I'm using MS Visual C++ 6.0
  • I have a Win32 DLL project which is compilable.
  • I have another project, this time a Win32 Console project which uses the DLL by including it's header file and linking the .lib file of the DLL.

Now I want to have another project, similar to the second BUT without using the header file and the lib file.

Is that possible? Everywhere I read you need either dll+lib+h or dll+h. If thought if you know the interfaces, a DLL file is sufficient?

Btw, by "using a DLL" I mean, using the Classes and Functions defined in the DLL.

回答1:

It is possible if you just have plain "extern C" functions. If this is the case the approach could be loading the dll with LoadLibrary, and then import each function with GetProcAddress, of course you need to know the function signature to create a properly declared function pointer. Using classes per contrary is almost impossible.



回答2:

If your DLL contains classes, there are good chances that it is a COM component.

If this is the case, the #import directive (that you use like #include) builds some temporary include files containing the interface details. You should use COM to access your objects.

Otherwise, if you have a 'plain' DLL with C++ classes, you could access the exported symbols using linker: instruct it to dump the map (see here), to know the mangled names. But I don't think that's possible to build manually the interface...