473,749 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invoke and InvokeMember methods work differently!?

Hi,
On Google, one can find a lot of statements that Invoke and
InvokeMemeber work alike. However, my own experience contradicts this
statement.

1. Surprisingly, Invoke and InvokeMember methods work differently!
I'm working with some legacy COM. The COM object (CMyCOM) implements
an interface that is not dual. The interface has a method, let say,
HRESULT Foo();
The corresponded coclass defines an interface
coclass MyCOM
{
[default] interface ITheInterface;
};
My C# client successfully calls Foo() method:
directly
MyCOMClass mcc = new MyCOMClass();
mcc.Foo();
or indirectly using Invoke()
MyCOMClass mcc = new MyCOMClass();
Type mccType = mcc.GetType();
MethodInfo mi = mccType.GetMeth od("Foo");
mi.Invoke(mcc, null);

However, the following code (using InvokeMember()) does not work
MyCOMClass mcc = new MyCOMClass();
Type mccType = mcc.GetType();
mccType.InvokeM ember("Foo",
System.Reflecti on.BindingFlags .InvokeMethod, null, mcc, null);

It results in an exception "COM target does not implement IDispatch",
which is very reasonable. For me, it looks like the system could not
access IReflection interface. But it also means that Invoke and
InvokeMember use absolutely different mechanisms under the hood!
Can anybody explain me the difference and in which situation what
method must be used?

2. To resolve the situation I define dispinterface as a wrapper of a
legacy non-dual interface.
Dispinterface IDTheInterface
{
#interface ITheInterface;
}

And I make CMyCOM class to implement both ITheInterface and
IDTheInterface. That case, CMyCOM, of course, implements IDispatch.
CoClass now looks like
coclass MyCOM
{
[default] interface ITheInterface;
dispinterface IDTheInterface;
};
However, that case also, InvokeMemeber call returns "Invalid callee"
exception. If I send (just for testing purpose) wrong number of
parameters, exception is "Wrong number of parameters".
It looks like, the system knows the method signature however it could
not dispatch call to the method implementation.

Can anyone explain me:
1. What is the REAL difference between Invoke and InvokeMember?
2. How to make InvokeMember work without redefining legacy interface
as a dual one?
Environment: .NET, C#, C++.

Alex
Nov 16 '05 #1
0 3085

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4389
by: PJ | last post by:
Hello, I am trying to use late binding to call a COM object. I am trying to call a 'GetTables' method on the object. It's essentially a 'MetadataService' which is used to return the names of tables which are in a specific database. the first parameter to GetTables is "in only" (it's a
0
1266
by: Dominic | last post by:
Hi, I'm tring to call the DisableAutoMacros method (well I think it's a method) of the Word.WordBasic object. This is returned as a _ComObject so I can not access this method directly. I have tried the following:
1
1592
by: RickDee | last post by:
Hi. I need help badly here. I need to write a program to invoke methods ( static, public, nonstatic, with parameters, and etc ) from an exe file, but I keep facing problem. From all the notes that I read from internet, I realized that InvokeMember works for methods in class, but not when I have an exe ( right ?). My program looks like this :
1
6134
by: Rein Petersen | last post by:
Hi All, I'm invoking Type.InvokeMember() on a COM class (via COMInterop) through a generalized interface. However, each specialized instance (of the COMInterop generic interface) requires slightly different arguments for which I dynamically create the object arguments and it all works nicely. Problem is, in some instances, I have methods which require certain arguments to be referenced (ref string x,...etc). I'm not sure how I can...
12
6995
by: Gus | last post by:
Hi, I´m triying to invoke a member using reflection, but this member requiere two parameters, the first patrameter is a string and the second is a reference to a dataset (output parameter). The parameters has to be passed in an array of objects. I´ve tried something like this: object parameters = new object; parameters ="text";
1
3358
by: Jenny Fletcher | last post by:
I am trying to dynamically invoke a property of enumeration type but I can't find a way to get it to work. This is my code which works fine until I call InvokeMember and I get an ArgumentException. I've tried various combinations of parameters in my call to InvokeMember but can't find anything that does the job. Any help would be appreciated. Jenny Dim arrObj(0) As Object Dim objPInfo As PropertyInfo =...
3
5270
by: =?Utf-8?B?Sm9l?= | last post by:
I know that I have posted this question before, but it is still unresolved and I don't know where to turn to next. I have code that is creating a user (works fine), then sets the account flags (works fine) and then sets the password (fails). Here is the pertinent information: Ex.InnerException.Message: Logon failure: unknown user name or bad password. Ex.Message: Exception has been thrown by the target of an invocation.
4
1742
by: James | last post by:
Hello everyone, While loading a page (http://www.edmonton.ca/portal/server.pt?space=CommunityPage&control=SetCommunity&CommunityID=239) into a webbrowser control I use invokemember on the 'onclick' event from 'cmdBusStopScheduleSubmit' element - see below. ONCLICK ========= <input type="submit" name="cmdBusStopScheduleSubmit" value="Get Bus Stop
4
5815
by: puzzlecracker | last post by:
Say, I have classname string, static method string, parameters list (which is char). Can I use reflection to invoke the method?
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8256
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.