-
August 23rd, 2005, 03:43 AM
#1
COM Interface - InvokeMember
Hello
I'm are trying to dynamically invoke a COM interface using the InvokeMember method but I'm having problems with the output parameters; they're not being returned. It works fine for input and return parameters, though.
thank you
awni
-
August 23rd, 2005, 03:47 AM
#2
Re: COM Interface - InvokeMember
Hi
Do you mean the InvokeHelper()?
Plz, describe the problem further. Paste some code here... I think we can help you
Best regards, Alex Dronov
Let the poster of the answers know when they helped you: Click "Rate this post!
-
August 23rd, 2005, 05:00 AM
#3
Re: COM Interface - InvokeMember
ok, this is for a friend who doesn't seem to be able to reach codeguru forums for some reason, so i'm going to mediate
we're using c# to access a COM object, we have no idea what's inside it, we only have the interface. We manged to dynamically invoke a .NET assembly method (using the assembly, class and method names) and to get the output parameters, but whenever we try to invoke a method from a COM interface no output parameters are returned.
here's some code
================================================
string methodName = "MehtodName";
Type t = Type.GetTypeFromProgID("COM.ProgId");
object targetInstance = Activator.CreateInstance(t);
//Prepare input and output parameters
string param1 = "john";
long param2 = 0;
string param3 = "No Error";
object[] parameters = new object[]{param1, param2, param3};
//Set up the parameter modifiers.
//Order: pdIn, pdOut, pdLcid, pdRetval, pdOptional, and pdHasDefault
ParameterModifier inModifier = new ParameterModifier(1);
ParameterModifier outModifier = new ParameterModifier(2);
inModifier[0] = true;
outModifier[1] = true;
ParameterModifier[] modifiers = new ParameterModifier[3]{inModifier, outModifier, outModifier};
object ret = null;
try
{
//Invoke the target method
ret = t.InvokeMember(
methodName,
BindingFlags.Instance |
BindingFlags.Public |
BindingFlags.InvokeMethod,
null,
targetInstance,
parameters,
modifiers,
null,
null);
}
catch(System.Reflection.TargetInvocationException ex)
{
Log(ex.InnerException.ToString());
//exit the function
}
param2 = (long)parameters[1];
param3 = (string)parameters[2];
//do some work
================================================
awni
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|