Trouble calling COM Object Method from C# object
-
Here is the code I'm having trouble with:
Type oBB = Type.GetTypeFromProgID("MyNamespace.MyClass"); Object o = Activator.CreateInstance(oBB); //Call BuildBook Object oResult = oBB.InvokeMember("BuildBook", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] { (int)Job.JobID, @"\\folder\in\" + Job.FinalFile.ToString(), Convert.ToBoolean(Job.Contribidx) }); //Get the name of the type of object returned by BuildBook and its cName property Type oRes = oResult.GetType(); String sName = (String)oRes.InvokeMember("cName", BindingFlags.GetProperty, null, o, null);
The problem is that when I check sName, it gives me the cName property of MyClass rather than the cName property of the object returned by BuildBook. Does anyone see any obvious mistakes in my code?
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
-
Here is the code I'm having trouble with:
Type oBB = Type.GetTypeFromProgID("MyNamespace.MyClass"); Object o = Activator.CreateInstance(oBB); //Call BuildBook Object oResult = oBB.InvokeMember("BuildBook", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] { (int)Job.JobID, @"\\folder\in\" + Job.FinalFile.ToString(), Convert.ToBoolean(Job.Contribidx) }); //Get the name of the type of object returned by BuildBook and its cName property Type oRes = oResult.GetType(); String sName = (String)oRes.InvokeMember("cName", BindingFlags.GetProperty, null, o, null);
The problem is that when I check sName, it gives me the cName property of MyClass rather than the cName property of the object returned by BuildBook. Does anyone see any obvious mistakes in my code?
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
Shouldn't the statement: String sName = (String)oRes.InvokeMember("cName", BindingFlags.GetProperty, null, o, null); be String sName = (String)oRes.InvokeMember("cName", BindingFlags.GetProperty, null, oResult, null); -Phil
-
Shouldn't the statement: String sName = (String)oRes.InvokeMember("cName", BindingFlags.GetProperty, null, o, null); be String sName = (String)oRes.InvokeMember("cName", BindingFlags.GetProperty, null, oResult, null); -Phil
You da man Phil...you da man!
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.