Original Post
hello!
I''ve got a problem with getting address of procedure in dlls.
When I''m trying to get address of function in specified dll, the program crashes, and I don''t know why. Below I present the code:
--------
dll.cpp:
--------
dll_export int AddTwo(int a, int b)
{
return a+b;
}
--------
--------
dll.h:
--------
#define dll_export __declspec(dllexport)
extern dll_export int AddTwo(int a, int b);
--------
dll_main - program which reads the address of dll''s function:
-------------
dll_main.cpp:
-------------
typedef int (CALLBACK* LPFNADD) (int, int);
int main(int argc, char* argv[])
{
HINSTANCE hDll = LoadLibrary("dll.dll");
LPFNADD add = (LPFNADD) GetProcAddress(hDll, "AddTwo");
if(!add)
{
printf("Error");
FreeLibrary(hDll);
return 0;
}
else
{
printf("%d", add(2,4));
}
FreeLibrary(hDll);
return 0;
}
Does anybody know what''s wrong with the code?
I would be grateful for any help.