![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've a problem with Strings and MethodInfo Invoke. All Strings I give to the Method I invoke where cut to on sign (like char). |
#3
| |||
| |||
|
|
Hi, I've a problem with Strings and MethodInfo Invoke. All Strings I give to the Method I invoke where cut to on sign (like char). The parameters are in a object new object[] { "string1" , "string2", "string3" "string4", "string5", 11111, "string6" } I testet with '\0' or StringBuilder, nothing works. The string is always a char 's' with the invoke method. Does anyone know why or can give me a link. MethodInfo mi = moduleBuilder.GetMethod(function); return mi.Invoke(null, args) The DllImport function looks like that: [DllImport("demo.dll", CharSet = CharSet.Ansi)] public static extern int demoMethode(string filename, string password, string license_name, string license_key, int license_code, string options); I use the following Invoke Method: public static object Invoke1(string dllName, string function,object[] args, Type resultType) { Type[] argTypes = Type.GetTypeArray(args); CultureInfo ci = Thread.CurrentThread.CurrentCulture; AssemblyName asmName = new AssemblyName(); asmName.Name = "TempAssembly"; asmName.Version = new Version(1, 0, 0, 0); asmName.CultureInfo = ci; AssemblyBuilder asmBuilder = Thread.GetDomain().DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = asmBuilder.DefineDynamicModule("TempModule"); MethodBuilder methodBuilder = moduleBuilder.DefineGlobalMethod(function, MethodAttributes.Final | MethodAttributes.PinvokeImpl | MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, resultType, argTypes); Type dllImportType = typeof (DllImportAttribute); ConstructorInfo conInfo = dllImportType.GetConstructor(new Type[] {typeof (string)}); FieldInfo callingConvField = dllImportType.GetField("CallingConvention"); FieldInfo preserveSigField = dllImportType.GetField("PreserveSig"); FieldInfo charSetField = dllImportType.GetField("CharSet"); CustomAttributeBuilder attrBuilder = new CustomAttributeBuilder( conInfo, new object[] {dllName}, new PropertyInfo[0], new object[0], new FieldInfo[] { callingConvField, preserveSigField, charSetField }, new object[] {CallingConvention.Winapi, true, CharSet.Unicode} ); methodBuilder.SetCustomAttribute(attrBuilder); moduleBuilder.CreateGlobalFunctions(); MethodInfo mi = moduleBuilder.GetMethod(function); return mi.Invoke(null, args); } |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |