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. Multiple excel server problem

Multiple excel server problem

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelpquestion
6 Posts 2 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.
  • T Offline
    T Offline
    trioum
    wrote on last edited by
    #1

    I am running 2 excel files on my system . there are 2 excel.exe(server) showing in the process tab of taskmanager .when I called GetActiveObject() function I always get the pointer of same excel . never get of another excel file . how can I get the object of every excel server running in the process

    Trioum

    C 1 Reply Last reply
    0
    • T trioum

      I am running 2 excel files on my system . there are 2 excel.exe(server) showing in the process tab of taskmanager .when I called GetActiveObject() function I always get the pointer of same excel . never get of another excel file . how can I get the object of every excel server running in the process

      Trioum

      C Offline
      C Offline
      Cool_Dev
      wrote on last edited by
      #2

      http://support.microsoft.com/kb/238975 Office applications typically registers their the first instance only in the ROT. but they are supposed to register their individual documents in the ROT, so iterating through the ROT using IRunningObjectTable Interface may be the option to get the instance you want, provided you know the document which is opened with that instance.

      T 1 Reply Last reply
      0
      • C Cool_Dev

        http://support.microsoft.com/kb/238975 Office applications typically registers their the first instance only in the ROT. but they are supposed to register their individual documents in the ROT, so iterating through the ROT using IRunningObjectTable Interface may be the option to get the instance you want, provided you know the document which is opened with that instance.

        T Offline
        T Offline
        trioum
        wrote on last edited by
        #3

        can you help me with some source code

        Trioum

        C 1 Reply Last reply
        0
        • T trioum

          can you help me with some source code

          Trioum

          C Offline
          C Offline
          Cool_Dev
          wrote on last edited by
          #4

          eventhough multple instances of excel are running, only the first instance would have an entry in ROT. But all the instances registers the documents opened in them in ROT. Its the key to bind to that instance of excel. say, u have more than one instances of excel apps, and want to get the instance in which "MyExcel.xls" file is opened..

          void GetMyExcelInstance()
          {
          CApplication oExcelApp; //class wizard generated class for excel app

          CoInitialize(NULL);
          HRESULT hr;
          
          //Setup ROT
          IBindCtx \*piBindCtx = 0; 
          hr = CreateBindCtx( 0, &piBindCtx ); 
          
          IRunningObjectTable \*piROT = 0;
          hr = piBindCtx->GetRunningObjectTable(&piROT);
          
          //Enumerate registered objects
          IEnumMoniker \*piEnum = 0;
          hr = piROT->EnumRunning(&piEnum);
          
          piEnum->Reset();
          
          ULONG nFetched;
          IMoniker \*piMoniker = 0;
          
          bool bGot = false;
          while(piEnum->Next(1, &piMoniker, &nFetched) == S\_OK && !bGot) 
          {
          	// Get Display name, in our case can be the workbook (excel doc) name
          	LPOLESTR strName;
          	hr = piMoniker->GetDisplayName(piBindCtx, NULL, &strName);
          	CString csName(strName);
          	CoTaskMemFree(strName);
          
          	if(csName.Find(L"MyExcel.xls") != -1) //or you may compare against full path of MyExcel.xls file
          	{
          		//Bind to the object. In this case object is excel workbook.
          		IDispatch \*piDispObj = 0;
          		hr = piMoniker->BindToObject(piBindCtx, NULL, IID\_IDispatch, (void\*\*)&piDispObj);
          
          		CWorkbook oWorkBook(piDispObj); //class for excel workbook object
          		oExcelApp = oWorkBook.get\_Application();
          		
          		bGot = true;
          
          	}
          	piMoniker->Release();
          }
          
          piEnum->Release();
          piROT->Release();
          piBindCtx->Release();
          
          if(bGot)
          {
          	//do here with oExcelApp 
          
          }
          

          }

          do proper error checking.. :thumbsup:

          T 1 Reply Last reply
          0
          • C Cool_Dev

            eventhough multple instances of excel are running, only the first instance would have an entry in ROT. But all the instances registers the documents opened in them in ROT. Its the key to bind to that instance of excel. say, u have more than one instances of excel apps, and want to get the instance in which "MyExcel.xls" file is opened..

            void GetMyExcelInstance()
            {
            CApplication oExcelApp; //class wizard generated class for excel app

            CoInitialize(NULL);
            HRESULT hr;
            
            //Setup ROT
            IBindCtx \*piBindCtx = 0; 
            hr = CreateBindCtx( 0, &piBindCtx ); 
            
            IRunningObjectTable \*piROT = 0;
            hr = piBindCtx->GetRunningObjectTable(&piROT);
            
            //Enumerate registered objects
            IEnumMoniker \*piEnum = 0;
            hr = piROT->EnumRunning(&piEnum);
            
            piEnum->Reset();
            
            ULONG nFetched;
            IMoniker \*piMoniker = 0;
            
            bool bGot = false;
            while(piEnum->Next(1, &piMoniker, &nFetched) == S\_OK && !bGot) 
            {
            	// Get Display name, in our case can be the workbook (excel doc) name
            	LPOLESTR strName;
            	hr = piMoniker->GetDisplayName(piBindCtx, NULL, &strName);
            	CString csName(strName);
            	CoTaskMemFree(strName);
            
            	if(csName.Find(L"MyExcel.xls") != -1) //or you may compare against full path of MyExcel.xls file
            	{
            		//Bind to the object. In this case object is excel workbook.
            		IDispatch \*piDispObj = 0;
            		hr = piMoniker->BindToObject(piBindCtx, NULL, IID\_IDispatch, (void\*\*)&piDispObj);
            
            		CWorkbook oWorkBook(piDispObj); //class for excel workbook object
            		oExcelApp = oWorkBook.get\_Application();
            		
            		bGot = true;
            
            	}
            	piMoniker->Release();
            }
            
            piEnum->Release();
            piROT->Release();
            piBindCtx->Release();
            
            if(bGot)
            {
            	//do here with oExcelApp 
            
            }
            

            }

            do proper error checking.. :thumbsup:

            T Offline
            T Offline
            trioum
            wrote on last edited by
            #5

            //code is ok up to here CWorkbook oWorkBook(piDispObj); //class for excel workbook object // but as I called the following line errro occurs member not found oExcelApp = oWorkBook.get_Application();

            Trioum

            C 1 Reply Last reply
            0
            • T trioum

              //code is ok up to here CWorkbook oWorkBook(piDispObj); //class for excel workbook object // but as I called the following line errro occurs member not found oExcelApp = oWorkBook.get_Application();

              Trioum

              C Offline
              C Offline
              Cool_Dev
              wrote on last edited by
              #6

              did you generate wrapper classs for excel type library? those class members may vary in different visual studio versions. check your class for WorkBook object to see how it returns Application object. it may be by get_Application() or GetApplication() or by some other means...

              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