Ok so I'm trying to load a function from a DLL using GetProcAddress. I've got this DLL:
Code:
extern "C" __declspec(dllexport) HWND WINAPI WWNewWindow(WNDPROC lpfnWndProc, LPSTR lpszClassName,
LPSTR lpszWindowName, int x, int y,
int width, int height, DWORD dwStyle)
{
WNDCLASSEX wc;
HWND hWnd;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(wc);
wc.cbWndExtra = 0;
wc.hbrBackground = static_cast<HBRUSH> (GetStockObject(GRAY_BRUSH));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = NULL;
wc.lpfnWndProc = lpfnWndProc;
wc.lpszClassName = lpszClassName;
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW | CS_HREDRAW;
if (! RegisterClassEx(&wc)) return NULL;
hWnd = CreateWindow(NULL, lpszWindowName, dwStyle, x, y, width, height, NULL, NULL, NULL, NULL);
return hWnd;
}
With this trying to load it:
Code:
typedef HWND (WINAPI *lpfnWWNewWindow)(WNDPROC lpfnWndProc, LPSTR lpszClassName, LPSTR lpszWindowName,
int x, int y, int width, int height, DWORD dwStyle);
lpfnWWNewWindow WWNewWindow;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HRESULT LoadWindowWrapper()
{
HMODULE hmWindowWrapperDLL;
hmWindowWrapperDLL = LoadLibrary("WindowWrapper.dll");
if (! hmWindowWrapperDLL) return E_FAIL;
WWNewWindow = (lpfnWWNewWindow) GetProcAddress(hmWindowWrapperDLL, "WWNewWindow");
if (! WWNewWindow) return E_FAIL;
return S_OK;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
if (SUCCEEDED(LoadWindowWrapper()))
{
hWnd = WWNewWindow(WndProc, "D3DApp", "Hello Ace!", 0, 0, 300, 300, WS_OVERLAPPEDWINDOW);
if (! hWnd)
{
MessageBox(0, "Error creating window", "Error", MB_OK | MB_ICONERROR);
return 1;
}
}
else
{
MessageBox(0, "Error loading DLL", "Error", MB_OK | MB_ICONERROR);
return 1;
}
return 0;
}
But it doesn't retrieve the function address. I've stepped though it and get an Access Violation *something* at address 0x00000000 when it gets to the call in WinMain (if I remove the error checking in LoadWindowWrapper, obviously).
I can't see what's wrong with this. I hate this platform sometimes.