|
-
Oct 14th, 2003, 04:52 PM
#1
Thread Starter
Conquistador
DLLS using loadlibrary
If I use loadlibrary to load a dll, how would i import its functions
i.e.
dllname = pak.dll
extern "C" void EXPORT SetValue ( float version )
Is the name in the dll ?
The full procedure run-down would be greatly appreciated 
thanks
-
Oct 14th, 2003, 05:50 PM
#2
Code:
#include <windows.h>
// typedef return_type(calling_convention *pfFunctioName)(arguments)
typedef void(__cdecl *pfSetValue)(float);
int main()
{
// SetValue is a pointer to a function
pfSetValue SetValue;
// Load the dll
HMODULE hPak = LoadLibrary("pak.dll");
// Check to make sure it worked...
if (!hPak)
{
MessageBox(NULL, "Failed to Load Library", "Error", MB_OK);
return 1;
}
// Find the address of the function
// (note that the name may be mangled if this is a c dll)
SetValue = GetProcAddress(hPak, "SetValue");
// Check to make sure it worked...
if (!SetValue)
{
MessageBox(NULL, "Failed to Find Address", "Error", MB_OK);
return 1;
}
// call the function just like any other function.
SetValue(42.1);
return 0;
}
Last edited by sunburnt; Oct 14th, 2003 at 09:33 PM.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Oct 16th, 2003, 05:16 AM
#3
Thread Starter
Conquistador
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|