CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Multiple instance - MDI problem

    I have an application which invokes my dll app using loadlibrary.

    In my dll application i create few documents using this

    pDocTemplate = new CMultiDocTemplate(
    IDR_MDTYPE,
    RUNTIME_CLASS(CTestMDIDoc),
    RUNTIME_CLASS(CChildFrame),
    RUNTIME_CLASS(CTestMDIView));
    AddDocTemplate(m_pSettingsTemplate);

    and point m_pMainWnd with the newly created mainframe window everytime when new instance is required.
    m_pMainWnd = pMainFrame;

    Problem is when user invokes the same application twice and tries to show views in first instances it loads the view in the last instance created. It works absolutly fine with single instance.
    The document count keeps on increasing with the number of instances.

    I maintain pDocTemplate and open views using OpenDocumentFile.
    pDocTemplate->OpenDocumentFile(NULL);

    I guess it is to do with the lastly created and maintained mainframe?
    m_pMainWnd = pMainFrame;

    What would be the problem? and how to solve it?

    My requirement is first instances should show first instances views in its own mainframe window and second instances should show views in its own mainframe window.

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

    Re: Multiple instance - MDI problem

    Quote Originally Posted by brraj View Post
    I have an application which invokes my dll app using loadlibrary.

    In my dll application i create few documents using this
    What do you mean with a "dll application"? A VS project can either be a DLL or an application (or a static library), but not a combination of them.
    Quote Originally Posted by brraj View Post
    Code:
    pDocTemplate = new CMultiDocTemplate(
    		IDR_MDTYPE,
    		RUNTIME_CLASS(CTestMDIDoc),
    		RUNTIME_CLASS(CChildFrame),
    		RUNTIME_CLASS(CTestMDIView));
    	AddDocTemplate(m_pSettingsTemplate);
    Where is this code called from?
    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

  3. #3
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Re: Multiple instance - MDI problem

    Quote Originally Posted by D_Drmmr View Post
    What do you mean with a "dll application"? A VS project can either be a DLL or an application (or a static library), but not a combination of them.
    Its a regular dll.

    Quote Originally Posted by D_Drmmr View Post
    Where is this code called from?
    Inside the entry function of regular dll.

    extern "C" __declspec(dllexport) CWnd* RunDll( void* pPtr )

    multiple instances are created by calling LoadLibrary multiple times.

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

    Re: Multiple instance - MDI problem

    Quote Originally Posted by brraj View Post
    Inside the entry function of regular dll.

    extern "C" __declspec(dllexport) CWnd* RunDll( void* pPtr )
    AddDocTemplate is a member function of CWinApp, so the code in your OP must either be called from a member function of a class derived from CWinApp or you have defined your own global or member function AddDocTemplate. Please post actual code, instead of code snippets without context. I can't help if I have to guess where code is being called from.

    In any case, I don't think you should be running this kind of code form a DLL's entry point. From http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    Warning There are serious limits on what you can do in a DLL entry point. To provide more complex initialization, create an initialization routine for the DLL. You can require applications to call the initialization routine before calling any other routines in the DLL.
    Quote Originally Posted by brraj View Post
    multiple instances are created by calling LoadLibrary multiple times.
    No, the documentation of that function on MSDN states
    If the specified module is a DLL that is not already loaded for the calling process, the system calls the DLL's DllMain function with the DLL_PROCESS_ATTACH value.
    You can have multiple instances of your program - as separate processes - but you cannot load the same DLL more than once simultaneously within one process.
    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

  5. #5
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Re: Multiple instance - MDI problem

    @Drmmr - thanks for the help

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