Click to See Complete Forum and Search --> : LIB File Loading...


ChrisDeluca
August 23rd, 1999, 12:00 AM
I am about to create a DLL that needs to run on all Windows OS versions (95/98/NT/W2K) and only need to link a library file and load it's associated DLL when a specific printer driver has been loaded.

Any suggestions on how to avoid any potential pitfalls and idea's about how to make this as slick as possible would be greatly appreciated.

Thanks!

- Chris

August 23rd, 1999, 09:37 AM
To use a DLL dynamically, you need to be aware of function pointers. I still find the definitions tricky... When the DLL is loaded, then you can get the function pointers by telling the function names. If you are unshure about the names, you can use the quick view feature of the Windows Explorer (right-click on a DLL).


HINSTANCE hMyLib;
MYFUNCTIONTYPE fnMyFunction;

hMyLib = LoadLibrary("mystuff.dll"); // load the library
if (hMyLib == NULL) // not found
return FALSE;

fnMyFunction = (MYFUNCTIONTYPE) GetProcAddress(hMyLib, "MyFunction");
if (fnMyFunction==NULL)
return FALSE;
// get more function pointers here...



// now you can call the function
int nTest = fnMyFunction(0, 0, 0); // just an example



// ... your follow-up code


if (hMyLib != NULL)
FreeLibrary(hMyLib); // release the library, unload the dll