View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Sergei Emelyanenkov[_2_] Sergei Emelyanenkov[_2_] is offline
external usenet poster
 
Posts: 5
Default More about trying to automation multiple Excel instances

Jialiang, even though my COM/OLE skills leave much to be desired, I've
understood the main idea of your explanation. It seems, now we have a good
knowledge of multiple Excel instances automation. We know what we can and
what we can't to do. For justice' sake, there is one potential issue -
several Excel instances without opened books (please, don't think about me
the same what I think about our testers :) ... But, it's rather theoretical
problem then practical.

I'm completely satisfied with the answers to both my questions! My other
needs doesn't concern to this particular issue, so I'm going to submit it as
separate posts.

Thank you!

--
Best Regards,
Sergei Emelyanenkov



"Jialiang Ge [MSFT]" wrote:

Hello Sergei,

Thanks for your patience. I have almost found out the reason:

Let¡¯s start with a test I¡¯m taking.

In my computer, I start 2 instances of Excel to open 2 xls files
respectively. In the meantime, I open two Visual Studio 2005 processes for 2
solutions. The ROT status at the moment shows as this in ROT Viewer:

----------------------start------------------------
{!00024500-0000-0000-C000-000000000046}
{!00024500-0000-0000-C000-000000000046}
D:\test\book1.xls
D:\test\book2.xls

!VisualStudio.DTE.8.0:4600
!VisualStduio.DTE.8.0:4080
!{BA018599-1DB3-44F9-83B4-461454C84BF8}
!{BA018599-1DB3-44F9-83B4-461454C84BF8}
D:\test\solution1.sln
D:\test\solution2.sln
---------------------- end ------------------------

1. The two occurrences of {!00024500-0000-0000-C000-000000000046} are the
item monikers of Excel instances. They have the same hash value, and refer
to the same instance of Excel as we have already found.

2. D:\test\book1.xls and D:\test\book2.xls are the file monikers of the
Excel instances. We are able to differentiate the Excel instances with them.

3. !VisualStudio.DTE.8.0:4600 and !VisualStduio.DTE.8.0:4080 are the Item
Monikers for Visual Studio IDE. They have different displayed name (the
number to the right of the progID is the process ID), different hash value.
Using them to get a specific Visual Studio instance works very well as is
illustrated in the article
http://www.codeproject.com/KB/cs/aut...ualstudio.aspx.

4. !{BA018599-1DB3-44F9-83B4-461454C84BF8} and
!{BA018599-1DB3-44F9-83B4-461454C84BF8}
These two are the important findings in my investigations. They are the
CLSID of Visual Studio IDE, just as {!00024500-0000-0000-C000-000000000046}
is the CLSID of Excel. They have identical displayed name, hash value, and
other properties. When I change the code in
http://www.codeproject.com/KB/cs/aut...ualstudio.aspx to use
!{BA018599-1DB3-44F9-83B4-461454C84BF8} to search the VS entry in ROT, I get
the same result as Excel, i.e., all the entries refer to the same instance.

5. D:\test\solution1.sln and D:\test\solution2.sln are the file monikers of
VS instances. We are also able to differentiate the VS instances with them.

From the above test, I see VS actually did the same thing for ROT
registration as Excel, except the !VisualStudio.DTE.8.0:4600 ones. It seems
that VS registers the additional !VisualStudio.DTE.8.0:4600, and this
additional action enables us to differentiate the VS instances with Item
Moniker.

After further looking into it, I realize that the registration of
{!00024500-0000-0000-C000-000000000046} and
!{BA018599-1DB3-44F9-83B4-461454C84BF8} with the CLSID of the component is,
in fact, a standard process of ROT registration. They are the result of the
call ¡°RegisterActiveObject¡±.
http://msdn.microsoft.com/en-us/libr...51(VS.85).aspx
Base on my tests, RegisterActiveObject is designed to behave in this way:
when the CLSID has already been registered in ROT, the operation will be
neglected, i.e. the latter registration won¡¯t take effect. That¡¯s why our
use of {!00024500-0000-0000-C000-000000000046} always refers to the same (or
more precisely, the first) instance of Excel.

I believe the additional action of Visual Studio is the call of
¡°IRunningObject::Register¡±. This method allows us to define the customized
¡°displayed name¡± for each entry, e.g. !VisualStudio.DTE.8.0:4600, so that
each instance has a distinctive name. Because the ¡°standard¡± registration
of ROT only includes the call of ¡°RegisterActiveObject¡±, Excel and many
other application do not have the ROT entries like VS.

Sergei, is this explanation clear enough for you? I welcome your and other
community members¡¯ rectifications in case I make any mistakes in the
research.

By the way, Sergei. I get the product team¡¯s confirmation today about the
possibility of limiting Excel instance number to one. They tell me there are
no supported ways to do it because Excel is designed as a Single Use
(Multiple Instances) server.

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================


"Sergei Emelyanenkov" wrote in message
...
Hello Jialiang,
of course, it's interesting for me to know why Ecxel behave in this
manner! :)

Waiting impatiently for the results of your investigations.
--
Best Regards,
Sergei Emelyanenkov