I have a FSX gauge, and would like to subclass (replace the window procedure in order to process keyboard input).
After I wrote my code ("SetWindowLongPtr(GWL_WNDPROC)"), it works fine, but on exit I get an exception. Regardless I call SetWindowLongPtr() second time (to restore old windowproc), or not.
Cannot find what I did incorrectly. In my code I process 'my' keypress messages and return FALSE; for other messages I call old window procedure via CallWindowProc():
pFSX_WP receives values like 0x2012E413, which seems like valid. In debug mode I can see a lot of Win32 message handling functions in Call Stack, so the reason might be in unprocessed messages in message queue or something like that.
I tried a lot of ways: SetWindowLongPtr and SetWindowLongA; different places for calling (case PANEL_SERVICE_POST_INSTALL/PANEL_SERVICE_PRE_KILL vs DllMain
LL_PROCESS_ATTACH/DLL_PROCESS_DETACH). Nothing helped.
Here is my log from SetWindowLongPtr() return:
That is, second call of SetWindowLongPtr() returns address of my KeysHandler() correctly.
Any ideas?
After I wrote my code ("SetWindowLongPtr(GWL_WNDPROC)"), it works fine, but on exit I get an exception. Regardless I call SetWindowLongPtr() second time (to restore old windowproc), or not.
Cannot find what I did incorrectly. In my code I process 'my' keypress messages and return FALSE; for other messages I call old window procedure via CallWindowProc():
Code:
LRESULT CALLBACK KeysHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
//
// blah-blah skipped
//
if(GetKeyState(VK_CONTROL) & 0x8000)
nKbFlags |= 32;
//
// blah-blah skipped
//
int wmId = LOWORD(wparam);
if(bMsgForMe)
{
nKeyToSend = SOMEVALUE;
if(nKeyToSend >= 0)
{
pPtr->key_handler(nKeyToSend);
return FALSE;
}
}
return CallWindowProc((WNDPROC)pFSX_WP, hwnd, msg, wparam, lparam);
} // KeysHandler
Code:
//
// DLL main code, initialization
//
hFSWnd = FindWindow("FS98MAIN", NULL);
if (hFSWnd)
{
//pFSX_WP = GetWindowLong(hFSWnd, GWL_WNDPROC);
pFSX_WP = SetWindowLongPtr(hFSWnd, GWL_WNDPROC, (__int3264)(LONG_PTR)KeysHandler);
} // if
Code:
//
// DLL main code, deinitialization
//
SetWindowLongPtr(hFSWnd, GWL_WNDPROC, (__int3264)(LONG_PTR)pFSX_WP);
pFSX_WP receives values like 0x2012E413, which seems like valid. In debug mode I can see a lot of Win32 message handling functions in Call Stack, so the reason might be in unprocessed messages in message queue or something like that.
I tried a lot of ways: SetWindowLongPtr and SetWindowLongA; different places for calling (case PANEL_SERVICE_POST_INSTALL/PANEL_SERVICE_PRE_KILL vs DllMain
Here is my log from SetWindowLongPtr() return:
Code:
FSX_WindowProc: [0x2012E413], changed to MyDLL_WindowProc: [0x9239FB9].
MyDLL_WindowProc: [0x9239FB9], changed back to FSX_WindowProc: [0x2012E413].
Any ideas?
