Shaitan00 Posted March 30, 2009 Posted March 30, 2009 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 BOOL DoWork (LPCTSTR a, DWORD b = 5000, BOOL c = TRUE, UCHAR d = 10, UCHAR e = 0) [/Code] A.h [Code] A_DLLPORT BOOL DoWork (LPCTSTR a, DWORD b, BOOL c, UCHAR d, UCHAR e); [/Code] 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); [/Code] 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, Quote
Administrators PlausiblyDamp Posted March 31, 2009 Administrators Posted March 31, 2009 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 typedef BOOL (*DoWorkFunc)(LPCTSTR , DWORD , BOOL , UCHAR , UCHAR ); DoWorkFunc pDoWorkFunc = GetProcAddress (hModule, "DoWork"); might be closer to the right answer. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.