简体   繁体   English

“无效的托管/非托管类型组合”是什么意思?

[英]What does “Invalid managed/unmanaged type combination.” mean?

I have the following struct: 我有以下结构:

    [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];
    }

Based on the C++ struct: 基于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;

And the following function: 并具有以下功能:

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

Based on the C++ function: 基于C ++函数:

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: 但是告诉我一个错误:

Cannot marshal 'parameter #2': Invalid managed/unmanaged type combination. 无法编组'参数#2':无效的托管/非托管类型组合。

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)]

To

[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. 很高兴找到关于这个错误的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 '无法封送'返回值':无效的托管/非托管类型组合。' 用字符串数组编组委托时 - 'Cannot marshal 'return value': Invalid managed/unmanaged type combination.' while marshalling delegate with string array 从C#调用C ++ dll。 “无法封送'返回值':无效的托管/非托管类型组合。” - Calling C++ dll from C#. “Cannot marshal 'return value': Invalid managed/unmanaged type combination.” 无法封送“返回值”:无效的托管/非托管类型组合 - Cannot marshal 'return value': Invalid managed/unmanaged type combination 非非托管类型和托管类型之间有什么区别? - What's the difference between a non-unmanaged type and a managed type? 编程中的托管代码或非托管代码是什么? - What is managed or unmanaged code in programming? 在EMGU中“找不到合适的目录来加载非托管模块”是什么意思? - What does “No suitable directory found to load unmanaged modules” mean in EMGU? 无效访问内存位置 - 管理到非托管代码 - invalid access to memory location - managed to unmanaged code 托管代码和非托管代码,内存和大小有什么区别? - What is the difference in managed and unmanaged code, memory and size? 托管库和非托管库有什么区别? - What are the differences between managed and unmanaged libraries? .NET中“托管”与“非托管”资源的含义是什么? - What is meant by “managed” vs “unmanaged” resources in .NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM