Okay, I fixed the function and is using dllexport now too, but it still isn't working. I'm wondering if this isn't a compilation problem, does it compile and run fine for you?
main.cpp
Code:
#include <windows.h>
typedef __declspec(dllexport) int (WINAPI *CommProt)(int);
#define ReportError(x) MessageBox(0, TEXT(x), TEXT("Error"), MB_OK | MB_ICONERROR);
int WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
{
HMODULE hDLL = LoadLibrary("appext.dll");
if(hDLL == NULL)
ReportError("Load of DLL failed.");
CommProt CommFunc = (CommProt)GetProcAddress(hDLL,"Comm"));
// This is where the error happens, the GetProcAddress() call fails.
if(CommFunc == NULL)
ReportError("Capture of function failed.");
Comm(5); // This is where the program crashes.
FreeLibrary(hDLL);
hDLL = NULL;
return 0;
}
appext.cpp
Code:
#include <windows.h>
__declspec(dllexport) int WINAPI Comm(int nVar)
{
char szDom[MAX_PATH];
wsprintf(szDom, TEXT("Comm var %d."), nVar);
MessageBox(0, szDom, TEXT("Comm"), MB_OK | MB_ICONINFORMATION);
return 0;
}
BOOL APIENTRY DllMain(HANDLE hMod, DWORD ulCall, LPVOID lpRes)
{
return TRUE;
}
-Quaytrix