The function pointer stuff is very unstable - it wouldn't be worth the effort to try and debug code that uses it for something as simple as this.
You can intercept the message relatively easily:
Intercept.cpp
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <Globstruct.h>
#define EXPORT __declspec(dllexport)
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID )
{
return TRUE;
}
GlobStruct* Core = 0;
WNDPROC PreviousWndProc;
bool CloseActivated = false;
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Check message types
switch (uMsg)
{
// The close message has been received - flag it.
case WM_CLOSE:
CloseActivated = true;
return 0;
}
// Any messages not handled by this point are passed on to the original WndProc
return CallWindowProc(PreviousWndProc, hwnd, uMsg, wParam, lParam);
}
EXPORT void ReceiveCoreDataPtr(LPVOID CorePtr)
{
// Store the core pointer
Core = static_cast<GlobStruct*>( CorePtr );
// Redirect windows messages to our own WndProc
PreviousWndProc = reinterpret_cast<WNDPROC>(
SetWindowLong(Core->hWnd, GWL_WNDPROC, reinterpret_cast<LONG>(MainWndProc) )
);
}
EXPORT DWORD GetClose()
{
// If the flag is set, reset it, and return a 'true' result
if (CloseActivated)
{
CloseActivated = false;
return 1;
}
// Otherwise, return a false result
return 0;
}
EXPORT void SendClose()
{
// Reset the WndProc for the window back to it's original setting
SetWindowLong(Core->hWnd, GWL_WNDPROC, reinterpret_cast<LONG>(PreviousWndProc) );
// Now send the close message
PostMessage(Core->hWnd, WM_CLOSE, 0, 0);
}
resource strings
"CLOSE HIT[%D%?GetClose@@YAKXZ%"
"CLOSE WINDOW%0%?SendClose@@YAXXZ%"
DBPro code
sync rate 0
sync on
local CloseTime as dword
CloseTime = timer()-1
do
cls
if CLOSE HIT() = 1 then CloseTime = timer() + 500
if CloseTime > timer() then text 0, 0, "CLOSE has been hit"
if inkey$() = "q" then CLOSE WINDOW
sync
loop