472,993 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Newbie qustion about InvokeMember

All,

I'm not new to C# but I am new to the concept of calling a member
using Interop.

I can access 1 function and properties in an external dll no
problem....but I can't understand how I'm supposed to do something
which in VB seems simple by comparison.

I need to query a property on an object, that property should return a
pointer to an object of a different type.

In this case, I connect to "AppManager" and ask "AppManager" for a
pointer to its "Machines" Object.

I can successfully get Appmanager to return things like its version or
other public Fields, but I can't get it to return what I want.

Here is the code.

try
{
Type tAppMgr =
Type.GetTypeFromProgID("NetIQOLE.AppManager");
object oAppMgr =
System.Activator.CreateInstance(tAppMgr);
tAppMgr.InvokeMember(
"Logon",
BindingFlags.InvokeMethod,
null, oAppMgr,
new object[] { "CALNTMGT501", "QDB", @"removed",
"removed" });

object oVersion = tAppMgr.InvokeMember("Version",
BindingFlags.GetProperty, null, oAppMgr, null);

Debug.WriteLine(((string)oVersion)); // This
works!

// In this below; oMachines stays "null"...ie nothing
is returned.

object oMachines = tAppMgr.InvokeMember( //
"Machines",
BindingFlags.GetProperty | BindingFlags.GetField |
BindingFlags.IgnoreCase
, null, oAppMgr, null);

Type tMachines = oMachines.GetType();
object count = tMachines.InvokeMember("Count",
BindingFlags.GetField, null, oMachines, null);

Debug.WriteLine(count.ToString());
}
catch (Exception e)
{
Debug.WriteLine(e.InnerException.Message);
}
As equivalent call in VB would be something like

oMachines = oAppMgr.Machines

Any help appreciated!

Cliff.
Aug 12 '08 #1
0 1017

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.