-
February 14th, 2011, 07:05 AM
#1
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.
-
February 14th, 2011, 09:08 AM
#2
Re: Multiple instance - MDI problem
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.
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?
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
-
February 14th, 2011, 11:40 PM
#3
Re: Multiple instance - MDI problem
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.
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.
-
February 15th, 2011, 12:11 PM
#4
Re: Multiple instance - MDI problem
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
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.
Originally Posted by brraj
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
-
February 16th, 2011, 06:50 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|