C
Charles Calvert
All,
Am I correct in thinking that passing a class/struct with methods to a
C++ DLL that expects a C++ struct might be problematic? The addition
of the vtable will change the size of the structure, but will it be
placed after the data, which should allow the C++ code to write to the
correct portion of memory?
E.g.:
C++ struct:
struct FooStruct
{
int i;
char a;
};
C# code:
[DllImport("foo.dll")]
private static extern uint ExportedFunction(ref FooStruct fs);
public struct FooStruct
{
int i;
char a;
public FooStruct()
{
i = 0;
a = 'a';
}
}
public uint Function(ref FooStruct fs)
{
return ExportedFunction(ref fs);
}
Am I correct in thinking that passing a class/struct with methods to a
C++ DLL that expects a C++ struct might be problematic? The addition
of the vtable will change the size of the structure, but will it be
placed after the data, which should allow the C++ code to write to the
correct portion of memory?
E.g.:
C++ struct:
struct FooStruct
{
int i;
char a;
};
C# code:
[DllImport("foo.dll")]
private static extern uint ExportedFunction(ref FooStruct fs);
public struct FooStruct
{
int i;
char a;
public FooStruct()
{
i = 0;
a = 'a';
}
}
public uint Function(ref FooStruct fs)
{
return ExportedFunction(ref fs);
}