1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

launching dll from mfc exe...

Discussion in 'MFC' started by sujan.dasmahapatra, Oct 23, 2011.

  1. sujan.dasmahapatra

    sujan.dasmahapatra New Member

    Jun 11, 2009
    Likes Received:
    Trophy Points:
    Look Friends
    Now I am not calling the dll from not winn32 but from another mfc exe application. Where I have a button when I press it I should load the dll and launch the mainwindow. See my two apis
    void CClientRevProjDlg::OnBnClickedButton1()
     typedef VOID (*MYPROC)(HWND);
        HINSTANCE hinstLib;
        MYPROC ProcAdd;
        BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
     HWND h = AfxGetMainWnd()->GetSafeHwnd();
        // Get a handle to the DLL module.
        hinstLib = LoadLibrary(L"C:\\Users\\DasmahapatraS\\Projects\\Bhagavan_Cadem\\RevolutionProj\\debug\\RevolutionProj.dll");
        // If the handle is valid, try to get the function address.
        if (hinstLib != NULL)
            ProcAdd = (MYPROC) GetProcAddress(hinstLib, "runAppli");
        // Do add operation
        // If the function address is valid, call the function.
            if (fRunTimeLinkSuccess = (ProcAdd != NULL))
                (ProcAdd) (h);
            // Free the DLL module.
            fFreeResult = FreeLibrary(hinstLib);
        // If unable to call the DLL function, use an alternative.
        if (! fRunTimeLinkSuccess)
            printf("message via alternative method\n");
    //And in the dll App.cpp I have an extern "C" like this....
    extern "C" BOOL __declspec(dllexport) runAppli(HWND h)
    // HWND h = AfxGetMainWnd()->GetSafeHwnd();
     return true;
    With this when I press the run button from client exe, my dll mainwindow is shown but crashing and hanging for sometime. Please help me get rid of this problem someone Thanks a lot.
    Last edited by a moderator: Oct 24, 2011

Share This Page