Thread: trying to call Dialog Box from within dll

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    trying to call Dialog Box from within dll

    hello, here is the working dialog box i want to appear by calling the dll function DialogInvoke
    http://www.codeproject.com/Articles/3984/Customizing-the-quot-Browse-for-folder-quot-dialog

    it's working fine, but i need to somehow remake it so the dialog will pop up in another programm.

    so this is the code in my main function to load the dll

    Code:
    typedef LRESULT (*DisplayMyMessage_pfn)(HWND) ; 
         HMODULE hmod = LoadLibraryA("d:\\working BrowseForFolder\\BrowseForFolder\\release\\BrowseForFolder.dll");
        if (!hmod)
        {
          
             reportError ( "LoadLibrary failed" );
            return 1;
        }//if
     
        DisplayMyMessage_pfn dm = 
            (DisplayMyMessage_pfn)GetProcAddress(hmod, "DialogInvoke");
        if (!dm)
        {
            FreeLibrary(hmod);
          
              reportError ( "GerProcAddress failed" );
            return 1;
        }//if
     
        dm(0);
     
        FreeLibrary(hmod);
    also it seems i must create  DllMain function 
    HINSTANCE g_hInst = 0;


    seems i must define the DllMain function
    Code:
    BOOL WINAPI DllMain(HINSTANCE hInst, DWORD Reason, LPVOID Reserved)
    {
        if (Reason == DLL_PROCESS_ATTACH)
            ghInstance = hInst;
        return TRUE;
    }

    here is the DialogInvoke function i want to use as dll function
    Code:
    extern "C" __declspec (dllexport) int DialogInvoke ( )
    {
       DialogBox(ghInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MainDlgProc);
       return 0;
    }

    but the dialog simply doesn't appears

  2. #2
    Registered User MilleniumFalcon's Avatar
    Join Date
    Feb 2014
    Posts
    33
    Quote Originally Posted by bazelboday View Post
    hello, here is the working dialog box i want to appear by calling the dll function DialogInvoke
    http://www.codeproject.com/Articles/3984/Customizing-the-quot-Browse-for-folder-quot-dialog

    it's working fine, but i need to somehow remake it so the dialog will pop up in another programm.

    so this is the code in my main function to load the dll

    Code:
    typedef LRESULT (*DisplayMyMessage_pfn)(HWND) ; 
         HMODULE hmod = LoadLibraryA("d:\\working BrowseForFolder\\BrowseForFolder\\release\\BrowseForFolder.dll");
        if (!hmod)
        {
          
             reportError ( "LoadLibrary failed" );
            return 1;
        }//if
     
        DisplayMyMessage_pfn dm = 
            (DisplayMyMessage_pfn)GetProcAddress(hmod, "DialogInvoke");
        if (!dm)
        {
            FreeLibrary(hmod);
          
              reportError ( "GerProcAddress failed" );
            return 1;
        }//if
     
        dm(0);
     
        FreeLibrary(hmod);
    also it seems i must create  DllMain function 
    HINSTANCE g_hInst = 0;
    seems i must define the DllMain function
    Code:
    BOOL WINAPI DllMain(HINSTANCE hInst, DWORD Reason, LPVOID Reserved)
    {
        if (Reason == DLL_PROCESS_ATTACH)
            ghInstance = hInst;
        return TRUE;
    }
    here is the DialogInvoke function i want to use as dll function
    Code:
    extern "C" __declspec (dllexport) int DialogInvoke ( )
    {
       DialogBox(ghInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MainDlgProc);
       return 0;
    }
    but the dialog simply doesn't appears
    If you expect someone to help you, you need to post all the code relevant to the creation of the dialog box, which you haven't. The majority of what you've posted has been poorly formatted code that you don't seem to fully understand. You should probably take a step back and learn how to make a DLL first, and the basics of its structure. Then you can start talking dialog boxes.

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    2
    problem fixed, the answer lies here Dialogbox from within a DLL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-24-2008, 03:14 PM
  2. Calling up a dialog from a dialog handler function
    By Welder in forum Windows Programming
    Replies: 2
    Last Post: 11-03-2007, 10:45 PM
  3. Replies: 7
    Last Post: 10-10-2006, 11:03 AM
  4. Using a dll to call a dialog in OnInitDialog of another.
    By mhandlon in forum Windows Programming
    Replies: 1
    Last Post: 03-22-2006, 11:10 AM