473,815 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetTypeFro mProgID("NetIQO LE.AppManager") ;
object oAppMgr =
System.Activato r.CreateInstanc e(tAppMgr);
tAppMgr.InvokeM ember(
"Logon",
BindingFlags.In vokeMethod,
null, oAppMgr,
new object[] { "CALNTMGT50 1", "QDB", @"removed",
"removed" });

object oVersion = tAppMgr.InvokeM ember("Version" ,
BindingFlags.Ge tProperty, null, oAppMgr, null);

Debug.WriteLine (((string)oVers ion)); // This
works!

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

object oMachines = tAppMgr.InvokeM ember( //
"Machines",
BindingFlags.Ge tProperty | BindingFlags.Ge tField |
BindingFlags.Ig noreCase
, null, oAppMgr, null);

Type tMachines = oMachines.GetTy pe();
object count = tMachines.Invok eMember("Count" ,
BindingFlags.Ge tField, null, oMachines, null);

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

oMachines = oAppMgr.Machine s

Any help appreciated!

Cliff.
Aug 12 '08 #1
0 1084

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

Similar topics

0
421
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 doing wrong? Or if using InvokeMember on a remote object is just a bad idea? The reason I wish to use InvokeMember rather than to call the method directly is because I don't want to install the assembly describing
0
3089
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 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
1
6139
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...
0
1313
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 by normal means and by using the InvokeMember. By examining the underlying il code with ildasm, when attempting to pass by reference, the il code generates a box command so that a pointer to the actual data is passed. This is clearly seen with...
3
2324
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 in and object . Since this is a pointer reference being passed it must be invoked in a unsafe {} even thought the dynamically loaded class is a .Net entity. The following is the test code that I am using to try and load a short * into an object:...
3
10174
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 reference. How can I correctly pass the short by ref through a InvokeMember. using System; using System.Reflection; namespace TestByRef { class DoByRef
4
3015
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 use WMI with InvokeMember and Option Strict On. I'm getting an "Unknown Name" error in the following statement in the code below. objProp = typeObjProps.InvokeMember("Item", _
1
1875
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 five or six ip addresses that I attempt to add to IIS causes an System.Reflection.TargetInvocationException to be thrown. Here is the code that adds the addresses: static void SetIPSecurityProperty(string metabasePath, string member, string item)...
4
1980
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 reproduce the behavior: Public Class clsTest Public Structure userGroupStruc Dim User As Boolean ' User Account Dim Admin As Boolean ' Administration Account
0
9737
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
9613
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
10673
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...
1
10430
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9227
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
6899
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4360
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
3
3032
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.