473,386 Members | 1,693 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,386 software developers and data experts.

InvokeMember Woes

All,
I am trying to access a complex COM library with nested COM classes. In
order to get at a certain class you must call a method on class A and this
method will return a instance of COM class B. FOr instance the VB code looks
like this:

Public Function GetFee(sFeeCode As String) As Test.FeeCls
....
End Function

I've written code to access the method GetFee in Class A, but the object
returned from the InvokeMember is undefined. No exceptions are generated but
the COM class B is not instantiated. Here is the "late Bound" code:

object[] args = new object[1];
args[0] = "";

tyClsB = Type.GetTypeFromProgID("Test.FeeCls",true);
oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod, null,
oClsA, args, null, null, null);

The variable oClsB is not valid.

if I use the interop lib generated and write this code it works:

string strFeeTy = "a03";
Test.FeeCls clsB;

clsB = clsA.GetFee(ref strFeeTy);

Any help or tips would be appreciated...

Stan
Nov 17 '05 #1
5 2916
Stan,

I am curious, why not just use the early bound call? It will be quicker
than the late bound call. After all, VB is really just COM, which is
interface based, so you can access the interface (it will be prefixed by an
underscore) and cast your dynamically loaded type to that.

As for doing it dynamically, is an exception thrown, or it just returns
null upon return?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Stan" <St**@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
All,
I am trying to access a complex COM library with nested COM classes. In
order to get at a certain class you must call a method on class A and this
method will return a instance of COM class B. FOr instance the VB code
looks
like this:

Public Function GetFee(sFeeCode As String) As Test.FeeCls
...
End Function

I've written code to access the method GetFee in Class A, but the object
returned from the InvokeMember is undefined. No exceptions are generated
but
the COM class B is not instantiated. Here is the "late Bound" code:

object[] args = new object[1];
args[0] = "";

tyClsB = Type.GetTypeFromProgID("Test.FeeCls",true);
oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod, null,
oClsA, args, null, null, null);

The variable oClsB is not valid.

if I use the interop lib generated and write this code it works:

string strFeeTy = "a03";
Test.FeeCls clsB;

clsB = clsA.GetFee(ref strFeeTy);

Any help or tips would be appreciated...

Stan

Nov 17 '05 #2
> oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod, null,
oClsA, args, null, null, null);

How did you declare oClsB ?

Greetings,
Wessel
Nov 17 '05 #3
Thanks for the quick reply. This is 3rd party software and we get new
versions quite often. I do not want to have to recompile the code every
single time it is deployed. I believe when I get a new version I will need a
new interop. Thus late binding. The just returns null. I wrote a sample
app just like this and it worked. I'm starting to think it is the 3rd party
objects.

Stan

"Nicholas Paldino [.NET/C# MVP]" wrote:
Stan,

I am curious, why not just use the early bound call? It will be quicker
than the late bound call. After all, VB is really just COM, which is
interface based, so you can access the interface (it will be prefixed by an
underscore) and cast your dynamically loaded type to that.

As for doing it dynamically, is an exception thrown, or it just returns
null upon return?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Stan" <St**@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
All,
I am trying to access a complex COM library with nested COM classes. In
order to get at a certain class you must call a method on class A and this
method will return a instance of COM class B. FOr instance the VB code
looks
like this:

Public Function GetFee(sFeeCode As String) As Test.FeeCls
...
End Function

I've written code to access the method GetFee in Class A, but the object
returned from the InvokeMember is undefined. No exceptions are generated
but
the COM class B is not instantiated. Here is the "late Bound" code:

object[] args = new object[1];
args[0] = "";

tyClsB = Type.GetTypeFromProgID("Test.FeeCls",true);
oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod, null,
oClsA, args, null, null, null);

The variable oClsB is not valid.

if I use the interop lib generated and write this code it works:

string strFeeTy = "a03";
Test.FeeCls clsB;

clsB = clsA.GetFee(ref strFeeTy);

Any help or tips would be appreciated...

Stan


Nov 17 '05 #4
oClsB is delared:

object oClsB;

"Wessel Troost" wrote:
oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod, null,
oClsA, args, null, null, null);

How did you declare oClsB ?

Greetings,
Wessel

Nov 17 '05 #5
> Here is the "late Bound" code:

object[] args = new object[1];
args[0] = "";

tyClsB = Type.GetTypeFromProgID("Test.FeeCls",true);
oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod, null,
oClsA, args, null, null, null);

The variable oClsB is not valid.

If I use the interop lib generated and write this code it works:

string strFeeTy = "a03";
Test.FeeCls clsB;

clsB = clsA.GetFee(ref strFeeTy);

For one thing, the argument to GetFee() seems to differ. In the late
bound example you pass "", and in the interop example you pass "a03".
Does it make a difference if you pass "a03" in the late bound code?

A second difference is the "ref" you use in the interop example. You
don't pass that in the late bound example. You could by doing something
like this:

Args = new Object[1];
Args[0] = "a03";
// ParameterModifier, construct with #parameters
ParameterModifier ParMod = new ParameterModifier(1);
// Set VT_BYREF
ParMod[0] = true;
// Put in array
ParameterModifier[] ArrParMod = { ParMod };
object oClsB = tyClsA.InvokeMember("GetFee", BindingFlags.InvokeMethod,
null, oChild, Args, ArrParMod, null, null);

Does this produce any other results?

Greetings,
Wessel
Nov 17 '05 #6

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

Similar topics

0
by: Jared Hagel | last post by:
I can't use Type.InvokeMember(...) on a remote object. But when I use Type.InvokeMember(...) on a non-remote object in the exact same way, I don't have a problem. Does someone know what I'm...
0
by: Alex Zhitlenok | last post by:
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...
1
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...
0
by: Pat Ireland | last post by:
I continue to investigate issues with making explicit InvokeMember calls (necessary when dynamically loading classes). My quest lets me use a simple class to invoke another class's member method...
3
by: Patrick Ireland | last post by:
I am dynamically loading a class. One of the methods of the class takes a short * (by reference) argument. However, the InvokeMember call used to invoke the method of the class passings arguments...
3
by: Pat Ireland | last post by:
The following code shows what I am trying to do. The normal invocation of the CalcByRef produces the correct results, however, using the InvokeMember fails to correctly pass the single argument by...
4
by: Howard Kaikow | last post by:
I am trying to retrive some WMI properties using Option Strict On. This requires the use of InvokeMember. I know that there are alternative ways to get the values, but I want to learn how to...
1
by: tommyk | last post by:
I am writing a small program that reads a text file filled with a large number of IP addresses and attempts to add them to IIS so that they will be blocked. For some reason, about one in every...
4
by: adiel_g | last post by:
I am trying to set a value on a structure object dynamically using InvokeMember. After I call InvokeMember, the value on the Admin flag does not get updated. Here is the following sample code to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
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,...

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.