dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: calling program crash

  1. #1
    Join Date
    Mar 2018
    Posts
    11

    calling program crash

    Have a mainProg.exe that calls DLL1 (C++ DLL, no user/worker thread created) and DLL1 calls DLL2 (MFC DLL). Have no access to DLL2 code.

    Without FreeLibraryAndExitThread(h,0); the mainProg.exe crashes.

    Does this makes sense?.


    DLL1 DLlMain:
    Code:
    HINSTANCE h;
    
    BOOL WINAPI DllMain(
        HINSTANCE hinstDLL,  // handle to DLL module
        DWORD fdwReason,     // reason for calling function
        LPVOID lpReserved )  // reserved
    {
        switch( fdwReason ) 
        { 
            case DLL_PROCESS_ATTACH:
    	   h = hinstDLL;
                break;
    
            case DLL_THREAD_ATTACH:
                break;
    
            case DLL_THREAD_DETACH:
                break;
    
            case DLL_PROCESS_DETACH:
    	    FreeLibraryAndExitThread(h,0);
                break;
        }
        return TRUE;
    }
    Last edited by Y$EA; May 2nd, 2019 at 11:55 PM.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,728

    Re: calling program crash

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.1.6)

  3. #3
    Join Date
    Mar 2018
    Posts
    11

    Re: calling program crash

    please see the "DLL1 DLlMain:" above:

    Have a mainProg.exe that calls DLL1 (C++ DLL, no user/worker thread created) and DLL1 calls DLL2 (MFC DLL). Have no access to DLL2 code.

    DLL_PROCESS_ATTACH is called once.
    Without FreeLibraryAndExitThread(h,0); the mainProg.exe crashes and with FreeLibraryAndExitThread(h,0); the mainProg.exe upon exit , its process remains running. What is an alternative to avoid crash and quit the process cleanly?.
    Last edited by Y$EA; May 2nd, 2019 at 11:56 PM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,405

    Re: calling program crash

    Quote Originally Posted by Y$EA View Post
    please see the "DLL1 DLlMain:" above:

    Have a mainProg.exe that calls DLL1 (C++ DLL, no user/worker thread created) and DLL1 calls DLL2 (MFC DLL). Have no access to DLL2 code.

    DLL_PROCESS_ATTACH is called once.
    Without FreeLibraryAndExitThread(h,0); the mainProg.exe crashes and with FreeLibraryAndExitThread(h,0); the mainProg.exe upon exit , its process remains running. What is an alternative to avoid crash and quit the process cleanly?.
    So, what is your question?
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2018
    Posts
    11

    Re: calling program crash

    looking for a way to handle the "case DLL_PROCESS_DETACH:" in DLL1 so that mainProg exits gracefully. MainProg upon exit does not crash and its process stops running.
    Last edited by Y$EA; May 3rd, 2019 at 09:02 AM.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,006

    Re: calling program crash

    Quote Originally Posted by Y$EA View Post
    looking for a way to handle the "case DLL_PROCESS_DETACH:" in DLL1 so that mainProg exits gracefully. MainProg upon exit does not crash and its process stops running.
    Did you read the link 2kaud posted?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)