Click to See Complete Forum and Search --> : DLL question
Wynd
Oct 22nd, 2001, 08:03 PM
When I make a DLL, I include the .h file with all the function prototypes and stuff, and link with the .lib file. How can I use the DLL without having to link with the .lib file?
jim mcnamara
Oct 22nd, 2001, 08:27 PM
A .lib file is a library of routines that the linker picks & chooses from. It drags them, whole, into your dll. If you link statically.
Otherwise, the .lib file 'knows' whether the routine is external (like in kernel32.dll) or lives only in the .lib file. If it is external, the 'kernel32' dll reference is used. Not the actual code. If it's internal, the code gets copied into your .dll file. Whole.
Either way, your code will run. The only time you have the dll reference problem is if YOU, in your dll code, reference another external dll that is not found on other PC's. The external reference will be put into your code by the linker. But at runtime, the dll will fail. Or: if the .lib file references an wacko external dll, then you have the same problem. Most of the time this is not an issue. 99% of the time, I'd say.
SO: the only problem you will likely encounter is that you have to drag along the other, external dll you decided to use.
However.
For COM, all bets are off. We now enter IID's, CLSID's, and a new world of hurt with ActiveX dll's. Suffice it to say, it doesn't work the same.
Wynd
Oct 22nd, 2001, 08:30 PM
What? I was talking about getting the handle to the function, pointer to it, etc.
jim mcnamara
Oct 22nd, 2001, 10:39 PM
I'm sorry - you used the word link - which I took to mean a link edit -- what you do when you create a runtime module or dll from object code.
There is no handle or pointer to a dll entry-point, per se. It gets defined when you create your program and run it. This is assuming I didn't get the wrong meaning, again. Your code maintains a reference (kind of a pointer or handle ).
You can use function pointers to refer to a dll entry point, or any other function's entry point.
You define a function pointer like this:
int (* p)();
(*p)() = myfunction;
......
int myfunction(void){
}
p now points to the function entry point for myfunction.
Eventually, I may accidentally provide what you want....
CornedBee
Oct 23rd, 2001, 07:38 AM
Uh, I think this still isn't it.
You mean, if you want to use the DLL in your app, you include the header and link to the lib. And you want to know how to go without using the lib. Did I get this right?
You need the API functions LoadLibrary, FreeLibrary and GetProcAddress.
This may be not exact, I don't have a referance at hand:
HMODULE LoadLibrary(LPCTSTR szFileName);
loads a dll, name is provided in szFileName, returns handle
void* GetProcAddress(HMODULE hLib, LPCTSTR szFunctionName);
gets the address of the function szFunctionName in the dll hLib.
void FreeLibrary(HMODULE hLib);
Free resources used by the library.
All of this is very complicated and messy. If you have an import library, use it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.