Jump to content
Sign in to follow this  
MachTwo

Unload FSX WndProc

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Just let the destructor take care of it.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

>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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...