Awesome! I'm looking forward to the final release.
I forgot to post the modified files to show how I fixed the problem. Here they are below:
initDarkGDK.h
#ifndef _GDKLIB_INITPUREGDK_H
#define _GDKLIB_INITPUREGDK_H
#include <string>
#include <sys/stat.h>
#include <windows.h>
bool initDarkGDK(std::string dllName, std::string path);
#endif /* _GDKLIB_INITPUREGDK_H */
initDarkGDK.cpp
// include files
#include "initDarkGDK.h"
bool initDarkGDK(std::string dllName, std::string path = "")
{
typedef int (__cdecl *protoInitDarkGDK)();
HINSTANCE lib;
protoInitDarkGDK ptr;
char lastChar;
bool callOnce = false;
if (callOnce)
return false;
if (path.length()) {
lastChar = path.at(path.length() - 1);
if (lastChar != '/' && lastChar != '\\')
path += '\\';
}
// Attempt to load library, favoring the current directory
lib = LoadLibrary(dllName.c_str());
if (!lib)
lib = LoadLibrary((path + dllName).c_str());
ptr = (protoInitDarkGDK)GetProcAddress(lib, "InitDarkGDK");
if (!ptr) {
MessageBox(0, ("Failed to located " + dllName).c_str(), "Error",
MB_ICONERROR);
return false;
}
ptr();
callOnce = true;
return true;
}
simpleWindow.h
#ifndef _SIMPLE_WINDOW_H_
#define _SIMPLE_WINDOW_H_
#include <string>
#include <map>
#include <deque>
#include <ctime>
#include <windows.h>
LRESULT _PdkWindow_DefWndCallback(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam);
UINT windowEvent();
UINT waitWindowEvent(unsigned int delay);
HWND openWindow(int x, int y, int width, int height, std::string title, int style, bool centered);
#endif // _SIMPLE_WINDOW_H_
simpleWindow.cpp
#include "simpleWindow.h"
LONG globDgdkWndLock = 0;
std::map<DWORD, std::deque<UINT> > globDgdkWndMap;
LRESULT _PdkWindow_DefWndCallback(HWND hWnd, UINT umsg, WPARAM wParam,
LPARAM lParam)
{
switch (umsg) {
// Do not evaluate null messages
case WM_NULL:
break;
// Priory messages
case WM_CLOSE:
case WM_DESTROY:
globDgdkWndMap[GetCurrentThreadId()].push_front(umsg);
break;
default:
globDgdkWndMap[GetCurrentThreadId()].push_back(umsg);
break;
}
switch (umsg) {
case WM_CLOSE:
return 1;
}
return DefWindowProc(hWnd, umsg, wParam, lParam);
}
UINT windowEvent() {
typedef HANDLE (WINAPI *(pOpenThread))(DWORD, BOOL, DWORD);
UINT result = WM_NULL;
MSG msg;
DWORD threadID = 0;
DWORD currentThreadID = GetCurrentThreadId();
HANDLE hThread = 0;
HMODULE hLib = 0;
pOpenThread ptr = 0;
DWORD exitCode = 0;
// Purge any thread deques which no longer exist
for (std::map<DWORD, std::deque<UINT> >::const_iterator iter =
globDgdkWndMap.begin(); iter != globDgdkWndMap.end(); iter++)
{
threadID = iter->first;
if (!ptr) {
hLib = GetModuleHandle("kernel32.dll");
ptr = (pOpenThread)GetProcAddress(hLib, "OpenThread");
}
// Win2k and up
if (ptr)
hThread = ptr(THREAD_QUERY_INFORMATION, 0, currentThreadID);
GetExitCodeThread(hThread, &exitCode);
if (exitCode != STILL_ACTIVE) {
globDgdkWndMap.erase(threadID);
if (hThread)
CloseHandle(hThread);
}
}
if (!globDgdkWndMap[currentThreadID].empty()) {
result = globDgdkWndMap[currentThreadID].front();
globDgdkWndMap[currentThreadID].pop_front();
}
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return result;
}
UINT waitWindowEvent(unsigned int delay) {
unsigned int elapsedStart;
UINT event = windowEvent();
if (event)
return event;
elapsedStart = GetTickCount();
do {
event = windowEvent();
Sleep(delay);
}
while (!event && GetTickCount() - elapsedStart < delay);
return event;
}
HWND openWindow(int x, int y, int width, int height, std::string title,
int style = WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU |
WS_CLIPCHILDREN | WS_VISIBLE, bool centered = false)
{
WNDCLASS Wnd;
RECT rect;
HWND hWnd;
HINSTANCE hInstance = GetModuleHandle(0);
const char* className = "wndclass";
Wnd.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
Wnd.lpfnWndProc = (WNDPROC)_PdkWindow_DefWndCallback;
Wnd.cbClsExtra = 0;
Wnd.cbWndExtra = 0;
Wnd.hInstance = hInstance;
Wnd.hIcon = LoadIcon(NULL, IDI_WINLOGO);
Wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
Wnd.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
Wnd.lpszMenuName = 0;
Wnd.lpszClassName = className;
RegisterClass(&Wnd);
SetRect(&rect, 0, 0, width, height);
AdjustWindowRectEx(&rect, style, 0, WS_EX_WINDOWEDGE);
if (centered) {
x = GetSystemMetrics(SM_CXSCREEN)/2 - (rect.right - rect.left)/2;
y = GetSystemMetrics(SM_CYSCREEN)/2 - (rect.bottom - rect.top)/2;
}
hWnd = CreateWindowEx(WS_EX_WINDOWEDGE, className, title.c_str(), style, x,
y, rect.right - rect.left, rect.bottom - rect.top, 0, 0, hInstance, 0);
if (!hWnd)
return 0;
// Paint window
UpdateWindow(hWnd);
return hWnd;
}
TheComet