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

Thread: DoModal failed

  1. #1
    Join Date
    Dec 2008
    Posts
    9

    DoModal failed

    Hello,

    I created one MFC extension DLL (Say DllA) that uses another extension dll in which classes are exported. In DllA I have created a dialog. I made one exported function from the and that (DllA) function simply call DoModal() on the object of Dialog class.

    ShowAsaeDlg()
    {
    ADialog ADlg;
    ADlg.DoModal;
    }


    Also created one MFC application which uses above created dll and give call to the exported function. Code is as below.


    GetModuleFileName(NULL, szModulePath, MAX_PATH);
    GetShortPathName(szModulePath, szModulePath, MAX_PATH);
    _tcscat(szModulePath, _T("ADll.dll"));


    hAsaeDll = LoadLibrary (szModulePath);
    pfnShowAsaeDlg = (PFN_SHOWASAEDLG)GetProcAddress(hAsaeDll, "ShowAsaeDlg");
    pfnShowAsaeDlg();

    This simple code does not works. DoModal returns -1.

    Can anybody help me on this.

    Regards,
    Avirat
    Last edited by avirat; May 21st, 2010 at 06:43 AM.

  2. #2
    Join Date
    Apr 2008
    Posts
    133

    Re: DoModal failed

    You might have to switch the module state.
    Try doing this AFX_MANAGE_STATE(AfxGetStaticModuleState( )); in your exported Dll function.

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

    Re: DoModal failed

    Quote Originally Posted by avirat View Post
    ... Also created one MFC application which uses above created dll and give call to the exported function. Code is as below.
    Code:
    	GetModuleFileName(NULL, szModulePath, MAX_PATH);
    	GetShortPathName(szModulePath, szModulePath, MAX_PATH);
    	_tcscat(szModulePath, _T("ADll.dll"));
    
    
    	hAsaeDll = LoadLibrary (szModulePath);
    	pfnShowAsaeDlg = (PFN_SHOWASAEDLG)GetProcAddress(hAsaeDll, "ShowAsaeDlg");
            pfnShowAsaeDlg();
    This simple code does not works. DoModal returns -1.
    1. While using Windows APIs you must always check their return value:
    What does LoadLibrary return?
    What does GetProcAddress return?
    2. Why do you call GetShortPathName API? Why do you need to convert the full path name of your exe to short (MS DOS) format?
    3. Did you try to debug your code to see the results of all of these APIs and _tcscat calls?
    Victor Nijegorodov

  4. #4
    Join Date
    Dec 2008
    Posts
    9

    Re: DoModal failed

    I have checked return values of all the functions for simplicity, I have added code without return value check.


    Also I have tried with AFX_MANAGE_STATE(AfxGetStaticModuleState( )), but of no use.

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

    Re: DoModal failed

    Quote Originally Posted by avirat View Post
    I have checked return values of all the functions for simplicity, I have added code without return value check.
    So, please show us your real code (don't forget Code tags).

    Quote Originally Posted by avirat View Post
    Also I have tried with AFX_MANAGE_STATE(AfxGetStaticModuleState( )), but of no use.
    What does AFX_MANAGE_STATE have to do with MFC extension DLL?
    It is used only for regular DLLs

    How about my questions #2 and #3?
    Victor Nijegorodov

  6. #6
    Join Date
    Dec 2008
    Posts
    9

    Re: DoModal failed

    The original code is as above. I only removed the functions return values checks.

    I agree AFX_MANAGE_STATE is used with user dlls, I have just tried it.

    There is no special reason for short path. Whatever the path (short or long) we expect the same behavior.

    I have debugged the code all the values are OK.
    Last edited by avirat; May 21st, 2010 at 07:30 AM.

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

    Re: DoModal failed

    Quote Originally Posted by avirat View Post
    I have debugged the code all the values are OK.
    Unfortunately, the code snippet you posted in your OP contradict with this assertion!

    Well, perhaps your posted snippet was just wrong!?
    So you have checked that:
    • dll path was correct
    • LoadLibrary returned not FALSE
    • GetProcAddress returned not NULL
    Haven't you?

    Then perhaps, something was wrong with a dialog template (it was not found in the modules it was expected to be)? Or with some of controls?
    Did you try to debug and step in to CDialog:oModal?
    Victor Nijegorodov

  8. #8
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: DoModal failed

    Quote Originally Posted by avirat View Post
    This simple code does not works. DoModal returns -1.
    Could be that the resource of the dialog cannot be loaded. Have a look at AfxSetResourceHandle.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  9. #9
    Join Date
    Nov 2007
    Posts
    613

    Re: DoModal failed

    It might be an error regarding the controls in your dialog box. Have you tried to add the DS_NOFAILCREATE style to your dialog box ? It will create the dialog box even if errors occur.

  10. #10
    Join Date
    Dec 2008
    Posts
    9

    Re: DoModal failed

    I found another problem in the same applications described above. The only one change in above scenario is that my DllA extension DLL is now using another extension DLL in which classes are exported. The problem is that my application gets hang.


    I 've verified all the things

    * dll path was correct
    * LoadLibrary returned not FALSE
    * GetProcAddress returned not NULL

    All the above are OK.

    When I debugged that application, inside the DoModal() there is RunModalLoop at this particular point applications gets hang.

  11. #11
    Join Date
    Feb 2005
    Posts
    2,160

    Re: DoModal failed

    Do you have an override for OnIntiDialog()? If so, put a breakpoint there and see if it gets hit and step from there to find your problem. If not, then you'll need to give a little more detail including code.

  12. #12
    Join Date
    Dec 2008
    Posts
    9

    Re: DoModal failed

    I have tried with overriding OnInitDialog(), and after debugging there is no way to trace the problem. Because up-till this point going smoothly.

    Following is the code from the extension dll i.e from "ADll.dll"

    ShowAsaeDlg() // This is exported function.
    {

    // ADialog is the class derived from the another class that is exported from another
    // extension dll.

    ADialog ADlg;
    ADlg.DoModal;
    }


    Following is the code from the application (exe)

    GetModuleFileName(NULL, szModulePath, MAX_PATH);
    GetShortPathName(szModulePath, szModulePath, MAX_PATH);
    _tcscat(szModulePath, _T("ADll.dll"));


    hAsaeDll = LoadLibrary (szModulePath);
    pfnShowAsaeDlg = (PFN_SHOWASAEDLG)GetProcAddress(hAsaeDll, "ShowAsaeDlg");
    pfnShowAsaeDlg(); // calling the exported function

    As I said earlier inside the DoModal() there is RunModalLoop the application gets hang.

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)