Hello Phil,
From your post, my understanding on this issue is: you wonder why your COM
object does not expose its events in late binding and how to resolve it. If
I'm off base, please feel free to let me know.
According to your sample code, I think you are using VB.*NET*. In order to
get all the events of a COM object with .net Reflection, we could call
GetEvents() method on a System.Type object. In this post, it seems that
GetEvents() returns an empty array. As you said, it is because the object
type is System.__ComObject, and it does not expose any real type
information. .NET Reflection generally only understands managed metadata,
not COM's ITypeInfo. In order to let it discover the COM events, we need a
managed description of the COM types in an interop assembly, which is
called RCW. I did the following test to reproduce your issue:
As we know, we need Office Primary Interop Assembly (PIA) to automate
Office in .NET. If the PIA has already been installed, the line
CreateObject("Word.Application") will return an object of type:
Word.Application, and the call of Type.GetEvents() will return all the
public events of the word application object. But if we uninstall the
Office PIA and try the CreateObject again, it only returns a
System.__ComObject object and no event is returned in GetEvents() call.
To resolve the problem:
1. If the COM component is a self-designed one, we could manually create a
..net interop assembly by running tlbimp command on it. Then add the
reference to the primary dll in your project.
For more information about how to create a .net interop assembly, please
refer to the MSDN article
http://msdn2.microsoft.com/en-US/library/tw4zwhbe.aspx
2. If the COM component belongs to a product, like the COM component of
Office, we could search for their .NET PIA from product owner and install
the PIA in your computer.
3. If the COM component has no way to be retrieved, you may consider hook
up the events via IConnectionPoint interfaces. The KB article
http://support.microsoft.com/kb/811645/en-us gives an example. For more
information about COM events in .NET, please refer to
http://msdn2.microsoft.com/en-us/library/1hee64c7(VS.71).aspx
Please let me know if you have any other concerns, or need anything else.
Sincerely,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document:
http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.