从调用 CPP DLL 的 C# 参数的数据结构

Hui Liu-MSFT 40,786 信誉分 Microsoft 供应商
2024-04-15T08:51:46.1333333+00:00

我在我的 C# 程序中调用了 CPPDLL。以下是我的 C# 代码片段:

**public struct ImageData
    {
        public int imageSize;
        public byte[] image;
    }
   public struct CppImportInfo
    {
        public byte[] name { get; set; }
        public byte[] id;
        public int group;
        public byte[] company;
        public byte[] e_mail;
        public byte[] title;
        public byte[] note;
        public ImageData imageData;
    };
    class CDllWrapper
    {
        #region Dll interface
        public CDllWrapper() { }

         [DllImport("FRV_Dll",                                      //name of the dll
                    EntryPoint = "Face_Register",                       //name of function in dll
                    ExactSpelling = true,
                    CharSet = CharSet.Ansi,
                    CallingConvention = CallingConvention.Cdecl)]
    ......
}**

以下是我在 CPP DLL 上的代码片段:

**struct ImageData
{
    int imageSize;
    unsigned char* image;
};
struct ImportInfo
{
    char* name;
.......
    char* note;
    struct ImageData imageData;
};
//ensure naked export
extern "C"
{
    ......
    CPLUSPLUS_API int Face_Register(struct ImportInfo *imageData, int* retCode, char** retMessage);
   ...
}**

当我检查imageInfo->imageData.image时,我发现它是错误的。怎么会这样?

Note:此问题总结整理于:Data structure of parameters from C# calling CPP DLL

C++
C++
一种通用的高级编程语言,作为 C 编程语言的扩展而创建,除了用于低级别内存操作的功能外,还具有面向对象、泛型和功能性等特点。
67 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Jiale Xue - MSFT 34,201 信誉分 Microsoft 供应商
    2024-04-15T09:21:59.1566667+00:00

    >>我检查了imageInfo->imageData.image 详细的错误消息是什么?

    您的imageData是否已填充?

    请参考此线程


    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。

    注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助