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 my corresponding C # code:
[StructLayout(LayoutKind.Sequential, Pack = 1)] //I also tried not to specify Pack, but the same error occurred. 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; } public SnapRoundingOption(double pixelSize) :this(pixelSize, false, false, 1) { } } [DllImport("Face.dll")] public static extern void FaceGenerationDummy(SnapRoundingOption snapRoundingOption);
However, when I call FaceGenerationDummy with this test:
[Test] public void DummyTest() { SimpleInterop.FaceGenerationDummy(new SnapRoundingOption(10, true, false, 1)); }
I found that KdTrees is 0 in C ++ and not 1 as passed.
What have I done wrong?
Edit: I am using Visual Studio 2008 on 32-bit Windows 7, not sure if this helps.
Edit 2: Both sizeof(SnapRoundingOption) return the same number, 16.
c ++ c # interop
Graviton
source share