0

次の構造体定義があります。

#ifndef struct_emxArray_real_T
#define struct_emxArray_real_T
struct emxArray_real_T
{
    real_T *data;
    int32_T *size;
    int32_T allocatedSize;
    int32_T numDimensions;
    boolean_T canFreeData;
};
#endif /*struct_emxArray_real_T*/

PInvoke を介して C# で使用したいと考えています。構造体は行列を表すためのものです。どんな C# 構造体コードでも大歓迎です。ありがとう!

誰かがここで試みました:

[StructLayout(LayoutKind.Sequential, Size = 1)]
public unsafe struct mytype
{
public double* data;
public int* size;
public int allocatedSize;
public int numDimensions;
public bool canFreeData;
}

しかし、それを機能させませんでした。

4

1 に答える 1

2

C# structs do not support pointer types.

Instead, pointers must be ported as IntPtr; you can use the Marshal class to resolve the pointer.

Therefore, you should write something like

[StructLayout(LayoutKind.Sequential)]
public unsafe struct mytype
{
    public IntPtr data;
    public IntPtr size;
    public int allocatedSize;
    public int numDimensions;
    public bool canFreeData;
}

Check what size your boolean_T type is; you may need to use the [MarshalAs(...)] attribute to specify the correct size.

于 2013-02-17T19:12:08.730 に答える