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.