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
LIB_EXPORT
Status Open(Context ctx
, Type type
, qsizetype idx
, Info& Info
, Handle &handle
);
enum Status
{
/Statuses/
}
enum Type
{
/Types/
};
`
The C# declaration looks this:
`
[StructLayout(LayoutKind.Sequential)]
public struct Info
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] version;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] date;
public byte channels;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] serialNumber;
public uint speed;
}
[DllImport("lib", CallingConvention = CallingConvention.StdCall)]
public static extern Status Open(IntPtr context, Type type, int index, ref Info data, ref IntPtr handle);
`
This works in WinForms, but in Mono (Unity), the struct is not filled with values. I suspect that it's about different string marshalling in Mono and MS, but I can't figure out how to fix it.
The text was updated successfully, but these errors were encountered:
I'm trying to PInvoke (on Windows) a method which has a struct parameter with wchar_t[].
The C++ (Qt) declaration looks this:
`
#define MAX_FIELD_LEN (30)
typedef void* Context;
typedef void* Handle;
struct Info
{
wchar_t id[MAX_FIELD_LEN];
wchar_t version[MAX_FIELD_LEN];
wchar_t date[MAX_FIELD_LEN];
uint8_t channels;
wchar_t serialNumber[MAX_FIELD_LEN];
uint32_t speed;
};
#define LIB_EXPORT __stdcall
LIB_EXPORT
Status Open(Context ctx
, Type type
, qsizetype idx
, Info& Info
, Handle &handle
);
enum Status
{
/Statuses/
}
enum Type
{
/Types/
};
`
The C# declaration looks this:
`
[StructLayout(LayoutKind.Sequential)]
public struct Info
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] version;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] date;
public byte channels;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public char[] serialNumber;
public uint speed;
}
[DllImport("lib", CallingConvention = CallingConvention.StdCall)]
public static extern Status Open(IntPtr context, Type type, int index, ref Info data, ref IntPtr handle);
`
This works in WinForms, but in Mono (Unity), the struct is not filled with values. I suspect that it's about different string marshalling in Mono and MS, but I can't figure out how to fix it.
The text was updated successfully, but these errors were encountered: