I'm trying to load a DLL dynamically using LoadLibrary()
, which works, however I cannot then get the address of the function in the DLL that I'm trying to call.
DLL function: (in CPP file)
_declspec(dllexport) void MyDllFunc()
{
printf("Hello from DLL");
}
Calling code:
typedef void (*MyDllFuncPtr)();
int _tmain(int argc, _TCHAR* argv[])
{
HINSTANCE LoadMe;
LPCWSTR str = L"C:\\Users\\Tony\\Documents\\Visual Studio 2008\\Projects\\DLL Loading\\Release\\MyDll.dll";
LoadMe = LoadLibrary(str);
if(LoadMe != 0)
printf("Successfully Loaded!\r\n");
else
printf("Loading Failed \r\n" );
MyDllFuncPtr func;
func = (MyDllFuncPtr)GetProcAddress(LoadMe, "MyDllFunc");
if (func != NULL)
func();
FreeLibrary(LoadMe);
}
func returns NULL!!!
What am I doing wrong?
This is a Win32 Console project.