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.
Re: Multiple instance - MDI problem
Quote:
Originally Posted by
brraj
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
Code:
pDocTemplate = new CMultiDocTemplate(
IDR_MDTYPE,
RUNTIME_CLASS(CTestMDIDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CTestMDIView));
AddDocTemplate(m_pSettingsTemplate);
Where is this code called from?
Re: Multiple instance - MDI problem
Quote:
Originally Posted by
D_Drmmr
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
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.
Re: Multiple instance - MDI problem
Quote:
Originally Posted by
brraj
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
Quote:
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
multiple instances are created by calling LoadLibrary multiple times.
No, the documentation of that function on MSDN states
Quote:
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.
Re: Multiple instance - MDI problem
@Drmmr - thanks for the help