0

我正在尝试在 C# 中创建下面的结构,以便可以与我的 Lumenera CCD 进行通信。下面的代码取自 c++ 头文件。主要问题是匿名联合和嵌套结构部分。非常感谢您的任何帮助。一个等效的例子会很棒。

typedef struct {
        FLOAT exposure;        
        FLOAT gain;            
        union {
         struct {
          FLOAT gainRed;     
          FLOAT gainBlue;     
          FLOAT gainGrn1;     
          FLOAT gainGrn2;     
         };
         struct {
          FLOAT gainMag;     
          FLOAT gainCyan;     
          FLOAT gainYel1;     
          FLOAT gainYel2;    
         };
        };
      union
      {
           BOOL useStrobe;        
         ULONG strobeFlags;   
      };

} LUCAM_SNAPSHOT;
4

1 回答 1

1
[StructLayout(LayoutKind.Explicit)] 
public struct LUCAM_SNAPSHOT
{
    [FieldOffset(0)] public float exposure;
    [FieldOffset(4)] public float gain;
    [FieldOffset(8)] public float gainRed;
    [FieldOffset(8)] public float gainGrn1;
    [FieldOffset(8)] public float gainGrn2;
    [FieldOffset(12)] public float gainMag;
    [FieldOffset(12)] public float gainGrn1;
    [FieldOffset(12)] public float gainGrn2;
    [FieldOffset(12)] public float gainMag;
    [FieldOffset(16)] public byte useStrobe;
    [FieldOffset(16)] public int strobeFlags;
}

我认为它可能类似于上述内容。我还没有尝试过,但至少你有一个起点。

于 2013-02-04T12:28:51.273 回答