By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,221 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,221 IT Pros & Developers. It's quick & easy.

Checking existance of method in COM object

P: n/a
Hi!

I want to know if a certain member function is available in a COM object,
before I try to call it. I'm using late binding and when I know the member
exists, everything is fine. Here's the code:

Type t = Type.GetTypeFromProgID("RR_Ispol.Road");
object o = Activator.CreateInstance(t);
object[] parameters = { @"HzAlignment.txt",
@"HzAlignment.xml" };
Int32 result = (Int32)t.InvokeMember("ImportRoadHz",
BindingFlags.InvokeMethod,
null,
o,
parameters);

If the member ImportRoadHz isn't available in RR_Ispol.Road, a COMException
is thrown. How can I test if the member is there or not, before I try to
call it? Calling it and catching an exception doesn't seem to be the
optimal solution. Oh, I have to use late binding because I don't know the
interface in advance.

Thanks in advance!

--
Daniel
Aug 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

On Aug 15, 9:11 am, Daniel Lidström <some...@microsoft.comwrote:
If the member ImportRoadHz isn't available in RR_Ispol.Road, a COMException
is thrown. How can I test if the member is there or not, before I try to
What does t.GetMembers(...) show?
optimal solution. Oh, I have to use late binding because I don't know the
interface in advance.
Well, technically, getting the Type from the ProgID and creating an
instance of the Type could both throw, and I don't know how you'd test
those. And if you can actually instantiate a RR_Ispol.Road, isn't the
member not existing an exceptional case?

Aug 15 '07 #2

P: n/a
On Wed, 15 Aug 2007 00:55:13 -0700, UL-Tomten wrote:
On Aug 15, 9:11 am, Daniel Lidström <some...@microsoft.comwrote:
>If the member ImportRoadHz isn't available in RR_Ispol.Road, a COMException
is thrown. How can I test if the member is there or not, before I try to

What does t.GetMembers(...) show?
Reflection on the type shows this:

Type: System.__ComObject
Method: System.Runtime.Remoting.ObjRef CreateObjRef(System.Type)
Method: System.Object InitializeLifetimeService()
Method: System.Object GetLifetimeService()
Method: Int32 GetHashCode()
Method: Boolean Equals(System.Object)
Method: System.String ToString()
Method: System.Type GetType()
>optimal solution. Oh, I have to use late binding because I don't know the
interface in advance.

Well, technically, getting the Type from the ProgID and creating an
instance of the Type could both throw, and I don't know how you'd test
those. And if you can actually instantiate a RR_Ispol.Road, isn't the
member not existing an exceptional case?
I have received COM objects that are going to be used as plugins. The
problem is that there is no unique interface defined. Each plugin has an
interface called Road, but they're not the same. All I know is that the
plugin has a Road interface that exports 1-4 methods. I guess I have to try
them all to determine which methods are available.

--
Daniel
Aug 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.