4

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Jane
  • 234
  • 1
  • 4
  • 11
  • 1
    Why would you not want to use the headers? – Mat Dec 20 '11 at 16:46
  • 2
    How would you "know the interfaces" without a declaration of them? That typically goes in a header file. The .lib file helps the linker figure out that the DLL needs to be used. You can use LoadLibrary + GetProcAddress to do it the hard way. – Hans Passant Dec 20 '11 at 16:48
  • @Jane - I would imagine that the other Win32 DLL project that you think has no .h or .lib in fact does have them. Otherwise you would need to find the function and class signatures yourself (how, I don't know). I suspect that a thorough investigation of the project properties will reveal the "missing" declaration (the lib or headers). – Dennis Dec 20 '11 at 16:54
  • @All: Actually I have all the files (.dll, .h, .lib), so I know how to generate them. However, I want to release the .dll file for other people. And I thought it is common just to offer the dll file and a documentation describing all class and function interfaces. Am I wrong? – Jane Dec 21 '11 at 07:11
  • OK, I use the .lib and .h files now, turned out it's not a problem at all and everything works fine now. – Jane Dec 21 '11 at 12:42

2 Answers2

4

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.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • 2
    I think you could use classes if you had a factory function you could call in the DLL. Have a plain C function which creates and returns a pointer to the desired class instance. then you load the library, and use GetProcAddress on that factory function and call it to get the class. In fact you could use only 1 function in the DLL which gives you a root object that is used for all other interaction. – Nerdtron Dec 20 '11 at 16:53
  • @Nerdtron yes agree, but the dll has to be created with that strategy in mind. – Felice Pollano Dec 20 '11 at 16:58
1

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...

Community
  • 1
  • 1
CapelliC
  • 59,646
  • 5
  • 47
  • 90