1) Call LoadLibrary() to load the DLL.
2) Call GetProcAddress( ) to get the address of your function from the DLL. You will need the HMODULE from LoadLibrary() and a string with the function name. This address will be returned as a FARPROC.
3) Declare a function pointer of the correct arguments and return type.
4) Assign the FARPROC to this function pointer using a typecast.
5) Call your function using the pointer.
6) Call FreeLibrary() when you are done with the DLL and want to unload it. Use the HMODULE from LoadLibrary()
I don't even speak Microsoft C, and even I could understand what WFC's
explanation is all about:
[code=C]
// 1) Call LoadLibrary() to load the DLL.
HMODULE myLib= LoadLibrary("my DLL" /* maybe more params here */);
// 2) Call GetProcAddress( ) to get the address of your function from the DLL.
// You will need the HMODULE from LoadLibrary() and a string with the function
// name. This address will be returned as a FARPROC.
FARPROC myAddr= LoadLibrary(myL ib, "myFunc");
// 3) Declare a function pointer of the correct arguments and return type.
typedef int (*foo_t)(double ); // or whatever
// 4) Assign the FARPROC to this function pointer using a typecast.
foo_t foo= (foo_t)myAddr;
// 5) Call your function using the pointer.
printf("%d\n", foo(42.54);
// 6) Call FreeLibrary() when you are done with the DLL and want to unload it.
// Use the HMODULE from LoadLibrary()
FreeLibrary(myL ib);
[/code]
Oh Ok............. .
Maybe you coulkd but I could not.
I guess I need a lot more work eh?
And is Microsoft C the same as Turbo C from Borland?
I guess not; that LoadLibrary() function is a Microsoft-ism as far as I know; If the
Borland folks are a bit clever they'd use the POSIX standard dlopen(), dlclose()
and dlsym() method names.
Comment