Problem calling from VisualC++ 32 bits to a Visual Prolog DLL
Posted: 19 Aug 2023 21:16
Hi, I am using this code from Visual C++, LoadLibrary does load the library well, GetProcAddress finds the function inside the DLL, but when I call to the pointer-to-function, the application crashes.
What am I doing wrong? Typedef declaration maybe? Is there any similar working sample for Visual C++?
Here is the code:
What am I doing wrong? Typedef declaration maybe? Is there any similar working sample for Visual C++?
Here is the code:
Code: Select all
typedef void (__stdcall * LPFNEXPORTEDPREDICATE)(void);
void CMFCApplication3View::OnBnClickedLoadPrologDll()
{
HMODULE hMod = 0x0000;
wchar_t wszDLLPath[256];
char szFunctionName[100];
LPFNEXPORTEDPREDICATE lpfnExportedPredicate = NULL;
memset(wszDLLPath, 0, sizeof(wszDLLPath));
wcscpy(wszDLLPath, _T("libProlog.dll"));
strcpy(szFunctionName, "exportedPredicate");
hMod = LoadLibrary(wszDLLPath);
if (hMod)
{
lpfnExportedPredicate = (LPFNEXPORTEDPREDICATE)GetProcAddress(hMod, (LPCSTR)szFunctionName);
if (lpfnExportedPredicate)
{
lpfnExportedPredicate(); //Crashes here
}
FreeLibrary(hMod);
}
}