Issues with GetProcAddress from my DLL

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
Probably a pretty newbie question but I'm having a hard time how to correctly use GetProcAddress to gain access to a function in a DLL I wrote...

The following is in the a.dll file I created (the function I wish to expose):

A.cpp
Code:
BOOL DoWork (LPCTSTR a, DWORD b = 5000, BOOL c = TRUE, UCHAR d = 10, UCHAR e = 0)

A.h
Code:
A_DLLPORT BOOL DoWork (LPCTSTR a, DWORD b, BOOL c, UCHAR d, UCHAR e);

Now, in my actual application I am trying to load the dll function DoWork as follows:
Code:
   HMODULE hModule = LoadLibrary ("a.DLL");
   if (!hModule)
      {
      return;
      }

   BOOL (*DoWork) (LPCTSTR) = GetProcAddress (hModule, "DoWork");
   if (!DoWork)
      {
      FreeLibrary (hModule);
      return;
      }

   if (DoWork(something))
      {
      // do something //
      }
   FreeLibrary (hModule);

But this code doesn't compile, I get the following error:
error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void)' to 'int (__cdecl *)(const char *)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

At this point its a litte hit-and-miss, I'm doing some reading and searching on how to properly use GetProcAddress() but I can't find examples that illustrate using it in the context I am trying to ...

Any help, ideas, or hints would be greatly appreciated...
Thanks,
 
C++ isn't even close to being my strong point so anything I say is suspect, however I think the problem is the fact you aren't casting the return from GetProcAddress to the correct type.

Something like
Code:
typedef BOOL (*DoWorkFunc)(LPCTSTR , DWORD , BOOL , UCHAR , UCHAR );

DoWorkFunc pDoWorkFunc = GetProcAddress (hModule, "DoWork");
might be closer to the right answer.
 
Back
Top