A
A n g l e r
Hi all.
I've got the following code as a part of managed C++ library that is
loaded by a project in C#:
public ref class FlyCaptureEnumsAndStructsManaged
{
public:
typedef enum class FlyCaptureCameraModel { blabla, blabla2 };
typedef enum class FlyCaptureCameraType { blabla, blablabla, blamax =
0x7FFFFFFF };
[StructLayout(LayoutKind::Explicit, Pack=1 Size=2028)]
typedef ref struct FlyCaptureInfoEx
{
[FieldOffset(0)] int SerialNumber;
[FieldOffset(4)] FlyCaptureCameraType CameraType;
[FieldOffset(8)] FlyCaptureCameraModel CameraModel;
[FieldOffset(12), MarshalAs(UnmanagedType::ByValTStr, SizeConst=512)]
String^ pszModelName;
... blablabla
};
};
Now, I'm facing some alignment issue after this has been ported to x64
platform. I used to work with windows x86 and VS 2005, now am working
with VS 2008 and XP x64.
It looks that the offset FieldOffset(12) is for some reason treated as
an inappropriate layout as raised exceptions indicate this clearly. When
It definitely helps when I amend the offset position to FieldOffset(16).
I'm a bit puzzled cos I've tried to force alignment with Pack=1 and
Pack=4, though it still acts like it was specified Pack=8.
Just to stress out as well that the same structure built directly in C#
(even without specifying the pack size) seems to have the desired 4 byte
layout.
Do you have any clue what is going on here? Perhaps this all is down to
some compiler switches?
Thanks a lot,
Peter.
I've got the following code as a part of managed C++ library that is
loaded by a project in C#:
public ref class FlyCaptureEnumsAndStructsManaged
{
public:
typedef enum class FlyCaptureCameraModel { blabla, blabla2 };
typedef enum class FlyCaptureCameraType { blabla, blablabla, blamax =
0x7FFFFFFF };
[StructLayout(LayoutKind::Explicit, Pack=1 Size=2028)]
typedef ref struct FlyCaptureInfoEx
{
[FieldOffset(0)] int SerialNumber;
[FieldOffset(4)] FlyCaptureCameraType CameraType;
[FieldOffset(8)] FlyCaptureCameraModel CameraModel;
[FieldOffset(12), MarshalAs(UnmanagedType::ByValTStr, SizeConst=512)]
String^ pszModelName;
... blablabla
};
};
Now, I'm facing some alignment issue after this has been ported to x64
platform. I used to work with windows x86 and VS 2005, now am working
with VS 2008 and XP x64.
It looks that the offset FieldOffset(12) is for some reason treated as
an inappropriate layout as raised exceptions indicate this clearly. When
It definitely helps when I amend the offset position to FieldOffset(16).
I'm a bit puzzled cos I've tried to force alignment with Pack=1 and
Pack=4, though it still acts like it was specified Pack=8.
Just to stress out as well that the same structure built directly in C#
(even without specifying the pack size) seems to have the desired 4 byte
layout.
Do you have any clue what is going on here? Perhaps this all is down to
some compiler switches?
Thanks a lot,
Peter.