Problem during running multiple instance of an MFC application
-
Hi I'm facing some problem in standard MFC application. In my application, I'm able to run only 3 instances of my application simultaneously.That is, I'm able to open only three login screens at the same time, but I dont want this limitaton. I'm currently working in Windows XP. However, when I ran my application in Windows NT, only 4 instances can be run at a time. When I tried to open it fourth time in Windows XP, it is failing at the following line of code. //winfrm.cpp BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, LPCTSTR lpszMenuName, DWORD dwExStyle, CCreateContext* pContext) { HMENU hMenu = NULL; if (lpszMenuName != NULL) { // load in a menu that will get destroyed when window gets destroyed HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, RT_MENU); if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL) { TRACE(traceAppMsg, 0, "Warning: failed to load menu for CFrameWnd.\n"); PostNcDestroy(); // perhaps delete the C++ object return FALSE; }} m_strTitle = lpszWindowName; // save title for later if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext)) { TRACE(traceAppMsg, 0, "Warning: failed to create CFrameWnd.\n"); if (hMenu != NULL) DestroyMenu(hMenu); return FALSE; } return TRUE; } Also, I have the following thing in my code: //Inside ::InitInstance if (pDocTemplate = new CMultiDocTemplate(IDR_mdiflsTYPE, RUNTIME_CLASS(CmdiflsDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CmdiflsView) ) != NULL) cout<<"Successful" else cout<<"Failure" I am creating such 140 CMULTIDOCTEMPLATE (using new) objects for different menus. Somebody suggested me why above function is failed might be due to the following reason:- If you call the constructor(above Doctemplate) so many times, without freeing, then you probably reach a maximum space of Windows handles, if the constructor loads menu and other resources. That’s why next resource-allocation functions fails. Can you confirm that you really create and keep so many objects? So to check resource allocation/storage limitation problem, I applied logs as shown above and I got 140 "Successful" messages when I ran 4th instance. One more thing is that when I lessen the number of these doc templates to around 50, I am able to start 6-7 instanc
-
Hi I'm facing some problem in standard MFC application. In my application, I'm able to run only 3 instances of my application simultaneously.That is, I'm able to open only three login screens at the same time, but I dont want this limitaton. I'm currently working in Windows XP. However, when I ran my application in Windows NT, only 4 instances can be run at a time. When I tried to open it fourth time in Windows XP, it is failing at the following line of code. //winfrm.cpp BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, LPCTSTR lpszMenuName, DWORD dwExStyle, CCreateContext* pContext) { HMENU hMenu = NULL; if (lpszMenuName != NULL) { // load in a menu that will get destroyed when window gets destroyed HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, RT_MENU); if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL) { TRACE(traceAppMsg, 0, "Warning: failed to load menu for CFrameWnd.\n"); PostNcDestroy(); // perhaps delete the C++ object return FALSE; }} m_strTitle = lpszWindowName; // save title for later if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext)) { TRACE(traceAppMsg, 0, "Warning: failed to create CFrameWnd.\n"); if (hMenu != NULL) DestroyMenu(hMenu); return FALSE; } return TRUE; } Also, I have the following thing in my code: //Inside ::InitInstance if (pDocTemplate = new CMultiDocTemplate(IDR_mdiflsTYPE, RUNTIME_CLASS(CmdiflsDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CmdiflsView) ) != NULL) cout<<"Successful" else cout<<"Failure" I am creating such 140 CMULTIDOCTEMPLATE (using new) objects for different menus. Somebody suggested me why above function is failed might be due to the following reason:- If you call the constructor(above Doctemplate) so many times, without freeing, then you probably reach a maximum space of Windows handles, if the constructor loads menu and other resources. That’s why next resource-allocation functions fails. Can you confirm that you really create and keep so many objects? So to check resource allocation/storage limitation problem, I applied logs as shown above and I got 140 "Successful" messages when I ran 4th instance. One more thing is that when I lessen the number of these doc templates to around 50, I am able to start 6-7 instanc
Sounds to me like classic running out of resources. I've never seen a serious app which needed 50 MultidocTemplates, never mind 150, but there you go, there's always a first for everything. Then on top of that you try and run multiple instances of this. (More than 3 anyways). Sounds more like a test of how much abuse you can give the system before it breaks. BTW how many documents of each of the 150 types did you plan to have open at the same time in the multiple instances, and what would the average size of each document be. It sounds to me like a case of 'Back to the Drawing Board' Hope this is Helpful :)
Bram van Kampen
-
Hi I'm facing some problem in standard MFC application. In my application, I'm able to run only 3 instances of my application simultaneously.That is, I'm able to open only three login screens at the same time, but I dont want this limitaton. I'm currently working in Windows XP. However, when I ran my application in Windows NT, only 4 instances can be run at a time. When I tried to open it fourth time in Windows XP, it is failing at the following line of code. //winfrm.cpp BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, LPCTSTR lpszMenuName, DWORD dwExStyle, CCreateContext* pContext) { HMENU hMenu = NULL; if (lpszMenuName != NULL) { // load in a menu that will get destroyed when window gets destroyed HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, RT_MENU); if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL) { TRACE(traceAppMsg, 0, "Warning: failed to load menu for CFrameWnd.\n"); PostNcDestroy(); // perhaps delete the C++ object return FALSE; }} m_strTitle = lpszWindowName; // save title for later if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext)) { TRACE(traceAppMsg, 0, "Warning: failed to create CFrameWnd.\n"); if (hMenu != NULL) DestroyMenu(hMenu); return FALSE; } return TRUE; } Also, I have the following thing in my code: //Inside ::InitInstance if (pDocTemplate = new CMultiDocTemplate(IDR_mdiflsTYPE, RUNTIME_CLASS(CmdiflsDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CmdiflsView) ) != NULL) cout<<"Successful" else cout<<"Failure" I am creating such 140 CMULTIDOCTEMPLATE (using new) objects for different menus. Somebody suggested me why above function is failed might be due to the following reason:- If you call the constructor(above Doctemplate) so many times, without freeing, then you probably reach a maximum space of Windows handles, if the constructor loads menu and other resources. That’s why next resource-allocation functions fails. Can you confirm that you really create and keep so many objects? So to check resource allocation/storage limitation problem, I applied logs as shown above and I got 140 "Successful" messages when I ran 4th instance. One more thing is that when I lessen the number of these doc templates to around 50, I am able to start 6-7 instanc
First... this is the 3rd or 4th time I see the question, if you are the same user repeating question, you could tae a look to the answers of your previous posts. If not... take a look on them, maybe you find the solution. Second... Why do you want to make different instances of application? Can't you just make, different pairs Doc-View in just one instance of your application?
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)
-
Hi I'm facing some problem in standard MFC application. In my application, I'm able to run only 3 instances of my application simultaneously.That is, I'm able to open only three login screens at the same time, but I dont want this limitaton. I'm currently working in Windows XP. However, when I ran my application in Windows NT, only 4 instances can be run at a time. When I tried to open it fourth time in Windows XP, it is failing at the following line of code. //winfrm.cpp BOOL CFrameWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, LPCTSTR lpszMenuName, DWORD dwExStyle, CCreateContext* pContext) { HMENU hMenu = NULL; if (lpszMenuName != NULL) { // load in a menu that will get destroyed when window gets destroyed HINSTANCE hInst = AfxFindResourceHandle(lpszMenuName, RT_MENU); if ((hMenu = ::LoadMenu(hInst, lpszMenuName)) == NULL) { TRACE(traceAppMsg, 0, "Warning: failed to load menu for CFrameWnd.\n"); PostNcDestroy(); // perhaps delete the C++ object return FALSE; }} m_strTitle = lpszWindowName; // save title for later if (!CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pParentWnd->GetSafeHwnd(), hMenu, (LPVOID)pContext)) { TRACE(traceAppMsg, 0, "Warning: failed to create CFrameWnd.\n"); if (hMenu != NULL) DestroyMenu(hMenu); return FALSE; } return TRUE; } Also, I have the following thing in my code: //Inside ::InitInstance if (pDocTemplate = new CMultiDocTemplate(IDR_mdiflsTYPE, RUNTIME_CLASS(CmdiflsDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CmdiflsView) ) != NULL) cout<<"Successful" else cout<<"Failure" I am creating such 140 CMULTIDOCTEMPLATE (using new) objects for different menus. Somebody suggested me why above function is failed might be due to the following reason:- If you call the constructor(above Doctemplate) so many times, without freeing, then you probably reach a maximum space of Windows handles, if the constructor loads menu and other resources. That’s why next resource-allocation functions fails. Can you confirm that you really create and keep so many objects? So to check resource allocation/storage limitation problem, I applied logs as shown above and I got 140 "Successful" messages when I ran 4th instance. One more thing is that when I lessen the number of these doc templates to around 50, I am able to start 6-7 instanc
Hi Chirag, Did you found a solution, I am running into the same issue. Thanks, Priyank