I have the following structure in C++:
extern "C" __declspec(dllexport) struct SnapRoundingOption
{
double PixelSize;
bool IsISR;
bool IsOutputInteger;
int KdTrees;
};
And this is my function declaration in C++:
extern "C" __declspec(dllexport) void FaceGenerationDummy(SnapRoundingOption snapOption);
This is the corresponding C# code:
// I also tried not specifying Pack, but the same error occurred.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SnapRoundingOption
{
public double PixelSize;
public bool IsISR;
public bool IsOutputInteger;
public int KdTrees;
public SnapRoundingOption(double pixelSize, bool isISR, bool isOutputInt, int kdTrees)
{
PixelSize = pixelSize;
IsISR = isISR;
IsOutputInteger = isOutputInt;
KdTrees = kdTrees;
}
}
[DllImport("Face.dll")]
public static extern void FaceGenerationDummy(SnapRoundingOption snapRoundingOption);
However, when I call the FaceGenerationDummy with this test:
[Test]
public void DummyTest()
{
SimpleInterop.FaceGenerationDummy(new SnapRoundingOption(10, true, false, 1));
}
I found that KdTrees is 0 in C++, instead of 1 as passed in.
What am I doing wrong?
Edit 1: I am using Visual Studio 2008 on Windows 7 32-bit.
Edit 2: Both sizeof(SnapRoundingOption) return the same number – 16.
Packand don't specifyPack, none which worked.intto be 32 bits wide?struct? Is that a typo or is it actually what you wrote?!PackandMarshalAsattributes/parameters.