VC++ DLL problem
I''m still having a problem with explicitly linking DLLs.
//DLL source:
#include <iostream.h>
void __declspec(dllexport) abc()
{ cout << "abc"; }
//EXE source
#include <windows.h>
int main()
{
HMODULE hDLL = LoadLibrary("dll.dll");
void (*abc)() = GetProcAddress(hDLL,"abc");
abc();
FreeLibrary(hDLL);
return 0;
}
Whenever I try this the program freezes. I debugged it and it turns out that the value of abc is 0x0000. Does anyone know what i''m doing wrong?
Here comes the Thnikkaman!
Is LoadLibrary() completing succesfully? Try checking the return value. And remember GetLastError() is your friend.
put extern "C" around the abc function.
//DLL source:#include <iostream.h>extern "C"{void __declspec(dllexport) abc(){ cout << "abc"; }}
THX!!! That extern "C" finally made it work! I''ve had this problem for a long time...
Here comes the Thnikkaman!
Here comes the Thnikkaman!
Make sure you fully understand why the extern "C" worked - might save you some headache in the future
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement