Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Unload FSX WndProc

Featured Replies

  • Commercial Member

Has anyone successfully been able to unload a subclass of the FSX WndProc on exit? No matter where I call SetWindowLong to return the original WndProc, FSX crashes in AfxWinMain. I can unload the WndProc at any time before WM_CLOSE successfully (i.e. before the user closes FSX), after this any attempt to unload the WndProc fails (WM_CLOSE, PANEL_SERVICE_DISCONNECT, module_deinit, DLL_PROCESS_DETACH) all have the same results. Hooking works fine, but I need to subclass. Any help or suggestions would be appreciated.

Andrew Wilson

sig_fslDeveloper.jpg

Just let the destructor take care of it.

  • Author
  • Commercial Member

Appreciate the suggestion, though this results in an unhandled exception error on exit.Have you been able to accomplish this in FSX?

Andrew Wilson

sig_fslDeveloper.jpg

>I can unload the WndProc at any time before WM_CLOSE>successfully (i.e. before the user closes FSX), after this any>attempt to unload the WndProc fails (WM_CLOSE,>PANEL_SERVICE_DISCONNECT, module_deinit, DLL_PROCESS_DETACH)>all have the same results. This behavior seems to suggest the reason behind the crash is that the object is no longer there after the WM_CLOSE. In other words, sounds like your destruction process is not what you may think. Just my best guess. Did you use a virtual destructor?You probably will need to post some code of the class.

  • Author
  • Commercial Member

Thanks again for your input Patrick. I'm using a global callback for the WndProc, so I'm not sure if this can be implemented as part of a class and then unloaded in the destructor?I agree the behaviour suggests that FSX is trying to references an object that is unavailable. As WM_CLOSE is the first message the program receives to exit, I doubt there is a way to unload the wndproc before this message is processed?Here are some snippets of my code, nothing special and works fine in FS9://Global Callbacks:/***********************************************/LRESULT CALLBACK MyWndProc( HWND, UINT, WPARAM, LPARAM );WNDPROC OldWndProc=NULL;HWND FShWnd;static HINSTANCE hDLLInstance;/***********************************************/LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){// Process any messages that we didn't take care of return ::CallWindowProc(OldWndProc, hwnd, msg, wparam, lparam);}/***********************************************/BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved){ switch(dwReason) { case DLL_PROCESS_ATTACH: { hDLLInstance = hDLL; FShWnd = FindWindow("FS98MAIN",NULL); OldWndProc = (WNDPROC) SetWindowLong(FShWnd, GWL_WNDPROC, (LONG)MyWndProc); }break; case DLL_PROCESS_DETACH: { if (OldWndProc) { SetWindowLong(FShWnd, GWL_WNDPROC, (LONG)OldWndProc); OldWndProc = NULL; } } }return TRUE;}

Andrew Wilson

sig_fslDeveloper.jpg

Instead of using a cached window handle in the DLL_PROCESS_DETACH code, you should use the FindWindow call to get the handle and make sure you aren't getting back the invalid handle value (INVALID_HANDLE I think is the constant, but check the docs for FindWindow to make sure). What is most likely happening is that your FSX DLL is being unloaded after the main FS window has already been destroyed, so your hook isn't installed anymore since the window went away, but under FS9 addon DLLs must have been unloaded before the main window was destroyed.

  • Author
  • Commercial Member

Thanks Tim

Andrew Wilson

sig_fslDeveloper.jpg

  • Author
  • Commercial Member

I've since resolved this by creating a new project and overriding InitInstance and ExitInstance. Thanks again for your help and suggestions.

Andrew Wilson

sig_fslDeveloper.jpg

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.