CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Posts
    231

    Showing dialog in DLL

    I create a dynamic library, using "MFC in a Shared DLL".

    I export a test method:

    h-file:
    Code:
    class CMyClass  
    {
    public:
      __declspec(dllexport) void Test();
    };
    cpp-file:
    Code:
    void CMyClass::Test()
    {
      CDialog1 dlg;
      dlg.DoModal();
    
      DWORD dw = GetLastError();
    }
    CDialog1 is just a new dialog created with resource editor. It's empty, except for buttons "OK" and "Cancel".

    When method "Test" is called from another MFC application, the dialog is not shown and GetLastError returns error 87 "The parameter is incorrect". I've also tried using macro AFX_MANAGE_STATE, but same error. (Attached zipped project).

    Please help. What parameter?? What do I need to add (or change) to show the dialog?
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Showing dialog in DLL

    Code:
      __declspec(dllexport) void Test();
    Instead of exporting a function, export the entire class.

    Code:
     __declspec(dllexport)class CMyClass

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Showing dialog in DLL

    I've also tried using macro AFX_MANAGE_STATE, but same error.
    Code:
    void CMyClass::Test()
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    	CDialog1 dlg;
    	dlg.DoModal();
    
    	print_last_error();
    }
    Attached Images Attached Images   
    Last edited by Igor Vartanov; May 28th, 2012 at 10:58 AM.
    Best regards,
    Igor

  4. #4
    Join Date
    Aug 2006
    Posts
    231

    Re: Showing dialog in DLL

    Thanks Igor!!

    Sorry about that. I was so certain that I already tried that. I must have made a mistake then, since it obviously works :-)

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Showing dialog in DLL

    When method "Test" is called from another MFC application, the dialog is not shown and GetLastError returns error 87 "The parameter is incorrect". I've also tried using macro AFX_MANAGE_STATE, but same error. (Attached zipped project).

    Please help. What parameter??
    The parameter it was about is dialog resource. As long as you failed to specify proper resource handle, the resource was searched in the .exe module resources (default resources). And obviously the search failed, and provided resource id was reported as invalid parameter.

    Funny thing, it might be a situation when the dialog resource with the same resource id could be there. In such case you would have some absolutely different dialog window attached to DLL class.
    Best regards,
    Igor

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured