什么"无效的托管/非托管类型组合&QUOT。意味着? [英] What does "Invalid managed/unmanaged type combination." mean?

查看:870
本文介绍了什么"无效的托管/非托管类型组合&QUOT。意味着?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构:

    [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 ++结构:

Based on the C++ struct:

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 ++函数

Based on the C++ function:

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

我称之为是这样的:

Which I call like this:

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

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

But get an error telling me:

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

Cannot marshal 'parameter #2': Invalid managed/unmanaged type combination.

这是什么意思?为什么会出现这种问题?我怎样才能克服它?所有的建议表示欢迎!

What does that mean? Why does it occur? How can I overcome it? All suggestions welcome!

推荐答案

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

Turns out all I needed to do was change:

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

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

由于问题是关于不仅仅是如何解决这个问题,我会离开它打开一会儿。它会是不错的了解更多一点关于此错误。

Since the question was about more than just how to solve it, I'll leave it open for a while. It'd be nice to find out a bit more about this error.

这篇关于什么"无效的托管/非托管类型组合&QUOT。意味着?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆