G
Gunnar Frenzel
Hello,
I have an application and dll both written in C#. The application uses methods and properties in the dll which works
fine so far, but I wasn't able use out parameters in methods call. I use the following structure to call the methods:
Assembly asmblyDll = Assembly.LoadFrom("theDll.dll");
Type tDll = asmblyDll.GetType("theDll.theDll");
object objDll = asmblyDll.CreateInstance("theDll.theDll");
string strToGet1 = string.Empty;
string strToGet2 = string.Empty;
ParameterModifier[] mods = new ParameterModifier[2] { new ParameterModifier(1), new ParameterModifier(1) };
mods[0][0] = true;
mods[1][0] = true;
object[] args = new object[2];
args[0] = strToGet1;
args[1] = strToGet2;
bool bRet = (bool)tDll.InvokeMember("theMethod", BindingFlags.InvokeMethod, null, objDll, args, mods, null, null);
theMethod is:
public bool theMethod(out string str1, out string str2)
{
str1 = "bla";
str2 = "blubb";
}
The ParameterModifier stuff was posted somewhere to use the parameters as out/ref parameters. But it didn't worked out.
Using ref in "theMethod" instead of out didn't work, too. The return value is correct and when the strToGet strings are
set to some strings then these are present in "theMethod" but changes to str1 and str2 didn't affect strToGet1 and
strToGet2.
Gunnar
I have an application and dll both written in C#. The application uses methods and properties in the dll which works
fine so far, but I wasn't able use out parameters in methods call. I use the following structure to call the methods:
Assembly asmblyDll = Assembly.LoadFrom("theDll.dll");
Type tDll = asmblyDll.GetType("theDll.theDll");
object objDll = asmblyDll.CreateInstance("theDll.theDll");
string strToGet1 = string.Empty;
string strToGet2 = string.Empty;
ParameterModifier[] mods = new ParameterModifier[2] { new ParameterModifier(1), new ParameterModifier(1) };
mods[0][0] = true;
mods[1][0] = true;
object[] args = new object[2];
args[0] = strToGet1;
args[1] = strToGet2;
bool bRet = (bool)tDll.InvokeMember("theMethod", BindingFlags.InvokeMethod, null, objDll, args, mods, null, null);
theMethod is:
public bool theMethod(out string str1, out string str2)
{
str1 = "bla";
str2 = "blubb";
}
The ParameterModifier stuff was posted somewhere to use the parameters as out/ref parameters. But it didn't worked out.
Using ref in "theMethod" instead of out didn't work, too. The return value is correct and when the strToGet strings are
set to some strings then these are present in "theMethod" but changes to str1 and str2 didn't affect strToGet1 and
strToGet2.
Gunnar