You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
can anyone tell me how to inject a struct like this
public struct test
{
public int cbS;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
public string Path;
}
my code is:
var test = new TypeDefinition("namespace_1", "test", TypeAttributes.Sealed | TypeAttributes.SequentialLayout | TypeAttributes.Public |
TypeAttributes.BeforeFieldInit, hMainMod.ImportReference(typeof(System.ValueType)));
var test_cb = new FieldDefinition("cb", Mono.Cecil.FieldAttributes.Public, hMainMod.TypeSystem.Int32);
var test_Path = new FieldDefinition("Path", Mono.Cecil.FieldAttributes.Public, hMainMod.TypeSystem.String);
hMainMod.Types.Add(test);
var FixedAttr = new FixedSysStringMarshalInfo();
FixedAttr.NativeType = NativeType.FixedSysString;
FixedAttr.Size = 255;
test_Path.DeclaringType = test;
test_Path.Attributes = Mono.Cecil.FieldAttributes.Assembly | Mono.Cecil.FieldAttributes.PInvokeImpl;
test_Path.InitialValue = new Byte[0];
test.Fields.Add(test_cb);
test.Fields.Add(test_Path);
the IL is:
.class public sequential ansi sealed beforefieldinit WindowsApplication1.test
extends [mscorlib]System.ValueType
{
// Fields
.field public int32 cb
.field public marshal(fixed sysstring[255]) string Path
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
can anyone tell me how to inject a struct like this
public struct test
{
public int cbS;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
public string Path;
}
my code is:
var test = new TypeDefinition("namespace_1", "test", TypeAttributes.Sealed | TypeAttributes.SequentialLayout | TypeAttributes.Public |
TypeAttributes.BeforeFieldInit, hMainMod.ImportReference(typeof(System.ValueType)));
var test_cb = new FieldDefinition("cb", Mono.Cecil.FieldAttributes.Public, hMainMod.TypeSystem.Int32);
var test_Path = new FieldDefinition("Path", Mono.Cecil.FieldAttributes.Public, hMainMod.TypeSystem.String);
hMainMod.Types.Add(test);
var FixedAttr = new FixedSysStringMarshalInfo();
FixedAttr.NativeType = NativeType.FixedSysString;
FixedAttr.Size = 255;
test_Path.DeclaringType = test;
test_Path.Attributes = Mono.Cecil.FieldAttributes.Assembly | Mono.Cecil.FieldAttributes.PInvokeImpl;
test_Path.InitialValue = new Byte[0];
test.Fields.Add(test_cb);
test.Fields.Add(test_Path);
the IL is:
.class public sequential ansi sealed beforefieldinit WindowsApplication1.test
extends [mscorlib]System.ValueType
{
// Fields
.field public int32 cb
.field public marshal(fixed sysstring[255]) string Path
} // end of class WindowsApplication1.test
but the IL not work well ,can anyone help me?
Beta Was this translation helpful? Give feedback.
All reactions