Hello friends!
I am trying to load DLL using loadlibrary function. DLL gets loaded properly, at least handle shows some non null value. But when I tried to get address for function using GetProcAddress method, I am getting "The specified procedure could not be found." error.
Can anybody explain what is wrong here?
Steps I followed
Created one Sample DLL application.
It contains one exported function
Created new console application
Included header file path of DLL using #include
Loaded DLL using LoadLibrary function.
have I missed some project specific settings??
Is this because of name mangling? Do I have to create .def file? I tried to create it but in which project it should have to include in DLL project or client project?
I tried to include the same in client but after that got linking error?
what are proper steps to achieve this goal?? I think I am missing something fundamental steps...
Yes I read that part. but I guess there is problem with name mangling. what I did now, provided input like
PADD pAdd = (PADD) GetProcAddress (hMod, "?Add@CSampleCalc@@QEAAHHH@Z");
and this works but something mess with calling convention
I used convention like...
typedef int (__cdecl * PADD) (int, int);
and when I tried to call this function using that proc address like pAdd (1,2)
and debuged that DLL function it receives parameters like 2, 0 HOW?
both side calling conventions are same
btw where do we have to set .def file in project setting of client project so that I can use decorated function name for GetProcAddress function??
?Add@CSampleCalc@@QEAAHHH@Z sound like you are using a C++ class. When you use GetProcAddress the most simpler way is to NOT use a class, use a plain function instead.
You can still use a class if you wish, but provide normal functions that wraps its members (as extern "C" as it is already said).