Hello all,
I have a problem to consult you and hope your help.
My work case like this:
---------------------
a VB6 COM DLL has a method ,Which has a Byref parameter
for return the changed value of the parameter;
calling the method above in .NET environment,such as c# ;
Using reflection rather than direct calling.
-------------------------------------
the class ProgID of VB6 is: MySimpleTest.TestClass,
the method code is:
-------------
Public Function mymethod(ByVal a As Integer, ByVal b As
Integer, ByRef c As Integer) As Integer
mymethod = a + b
c = a - b
End Function
----------------------------------------
----------------------------------------
the calling code in c# is:
------------
{
int i1 = 15;
int i2 = 6;
int i3 = 3;
object[] args ={i1,i2,i3};
MessageBox.Show(args[2].ToString(), "value of args[2]",
MessageBoxButtons.OK, MessageBoxIcon.None); //show "3"
Type T=Type.GetTypeFromProgID("MySimpleTest.TestClass") ;
object obj = Activator.CreateInstance(T);
string methodName = "mymethod";
bool [] byRef ={false,false,true};
ParameterModifier[] mods = new ParameterModifier[3];
for (int i = 0; i < 3; i++)
{
// create exactly one modifier
ParameterModifier m = new ParameterModifier(1);
m[0] = byRef[i]; // true? call by ref.
mods[i] = m;
}
object retVal = obj.GetType().InvokeMember(methodName,
BindingFlags.InvokeMethod, null, obj , args, mods, null,
null);
MessageBox.Show(retVal.ToString(), "result",
MessageBoxButtons.OK, MessageBoxIcon.None);//show "21"
MessageBox.Show(args[2].ToString(), "value of args[2]",
MessageBoxButtons.OK, MessageBoxIcon.None); //show "3"
//but the expected value of args[2] is "9"!
}
----------------------------------------------------
------------------------------------------------
Excuting the calling,the value of args[2] is still "3"!
Why? This problem bother me badly.
Would you please create the DLL in VB6 and test it ?
An early reply is appreciated.
Best regards.
Tom.