2011-04-15 76 views
4

我有以下结构:什么是“托管/非托管类型组合无效”。意思?

[StructLayout(LayoutKind.Auto,Pack=0)] 
    private unsafe struct BIRDSYSTEMCONFIG 
    { 
     public byte bySystemStatus; 
     public byte byError; 
     public byte byNumDevices; 
     public byte byNumServers; 
     public byte byXmtrNum; 
     public ushort wXtalSpeed; 
     public double dMeasurementRate; 
     public byte byChassisNum; 
     public byte byNumChassisDevices; 
     public byte byFirstDeviceNum; 
     public ushort wSoftwareRev; 
     public fixed byte byFlockStatus[127]; 
    } 

基于C++的结构:

typedef struct tagBIRDSYSTEMCONFIG 
{ 
    BYTE bySystemStatus;  // current system status (see bird system status bits, above) 
    BYTE byError;   // error code flagged by server or master bird 
    BYTE byNumDevices;  // number of devices in system 
    BYTE byNumServers;  // number of servers in system 
    BYTE byXmtrNum;   // transmitter number (see transmitter number bits, above) 
    WORD wXtalSpeed;   // crystal speed in MHz 
    double dMeasurementRate; // measurement rate in frames per second 
    BYTE byChassisNum;  // chassis number 
    BYTE byNumChassisDevices; // number of devices within this chassis 
    BYTE byFirstDeviceNum; // number of first device in this chassis 
    WORD wSoftwareRev;  // software revision of server application or master bird 
    BYTE byFlockStatus[BIRD_MAX_DEVICE_NUM + 1]; // status of all devices in flock, indexed by bird number (see note in BIRDFRAME definition) - see bird flock status bits, above 
} 
BIRDSYSTEMCONFIG; 

而下面的功能:

[DllImport(@"Bird.dll", CallingConvention = CallingConvention.Cdecl)] 
    private static extern bool birdGetSystemConfig(
     int nGroupID, 
     ref BIRDSYSTEMCONFIG psyscfg, 
     bool bGetDriverCopy 
     ); 

基于C++函数:

BOOL DLLEXPORT birdGetSystemConfig(int nGroupID, BIRDSYSTEMCONFIG *psyscfg, BOOL bGetDriverCopy = FALSE); 

我称之为是这样的:

BIRDSYSTEMCONFIG sysconf = new BIRDSYSTEMCONFIG(); 
birdGetSystemConfig(1, ref sysconf, true); 

但得到一个错误,告诉我:

不能元帅参数#2“:无效 管理/非托管类型组合。

这是什么意思?为什么会发生?我如何克服它?欢迎所有建议!

+0

您应该发布原始的C++结构。 – 2011-04-15 02:06:09

+0

好主意。编辑。 – 2011-04-15 02:10:10

+0

看看这里:http://www.groupsrv.com/dotnet/about24649.html – sajoshi 2011-04-15 02:38:41

回答

2

打开了所有我需要做的是改变:

[StructLayout(LayoutKind.Auto,Pack=0)] 

[StructLayout(LayoutKind.Sequential,Pack=0)] 

由于问题是关于不仅仅是如何解决这个问题,我会离开它打开一个更而。很高兴能够找出更多关于这个错误的信息。

相关问题