473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Checking existance of method in COM object

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
2 1474

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Uzi G. | last post by:
Hi, We have a JSP website intended for viewing with IE 5 (and above) On a certain jsp page, there are few span objects (<SPAN ID="name">text</SPAN>), which are created dynamically. The spans...
0
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to...
4
by: Lambuz | last post by:
Is there any way to check the existance of a window by the name ? I'm using this code: window.open("http://www.google.com",'targetWin1') If I open a window using previous code without getting...
7
by: Ajit | last post by:
Is there anyway to check for existance of a file on different machine. i.e. we have a data file (text file) thats stored on some other machine as its not to be exposed in case the web server is...
4
by: Iain Porter | last post by:
Hi all, I have a usercontrol (a textbox with dropdown calendar that fills the textbox with the selected date) that I implement in a datagrid in a webform. On first loading the page, the datagrid's...
5
by: A.M | last post by:
Hi, To check if QueryString contains a key I compaire it with null like this code: if (Request.QueryString!=null) { Label1.Text= Request.QueryString; } else
46
by: John | last post by:
Hi How can I check for existence of a certain table by name in and access database and if the table exists find the number of records in it? I guess I can access this information by setting up...
6
by: Andy B | last post by:
How do you check to see if a certain folder exists? I also need to know how to check for the existance of a certain sql server database table.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.