Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem during running multiple instance of an MFC application

Problem during running multiple instance of an MFC application

Scheduled Pinned Locked Moved C / C++ / MFC
c++wpfdebugginghelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chirag_kalra
    wrote on last edited by
    #1

    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

    B N P 3 Replies Last reply
    0
    • C Chirag_kalra

      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

      B Offline
      B Offline
      Bram van Kampen
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • C Chirag_kalra

        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

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #3

        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 ;)

        1 Reply Last reply
        0
        • C Chirag_kalra

          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

          P Offline
          P Offline
          Priyank Bolia
          wrote on last edited by
          #4

          Hi Chirag, Did you found a solution, I am running into the same issue. Thanks, Priyank

          http://www.priyank.co.in/

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups