如何将C ++结构转换为C#结构 [英] How do I convert C++ struct to a C# struct

查看:87
本文介绍了如何将C ++结构转换为C#结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将C ++结构转换为C#结构。通过使用这些结构,我将使用结构中的参数在函数上使用它。



C ++

Hi, Im trying to convert a C++ struct to a C# struct. By using these struct i will use the parameter from the struct to use it on a function.

C++

typedef unsigned char uint8;
typedef int sint32;
typedef struct BY_BITMAP
{
    sint32 biWidth;      
    sint32 biHeight;     
    sint32 biBitCount;   
    sint32 bfSize;       
    sint32 BytesPerLine; 
    uint8 **ScanLine;    
    uint8 *buffer;       
}BY_BITMAP;





在主程序中我会使用这些代码来代替功能





At the main program i would use these to code for the function

public void SavePic()
{
 ByBitmap[] sources = new ByBitmap[2];
            sources[0] = new ByBitmap();
            sources[0].buffer = null;
            sources[0].ScanLine = null;
            sources[1] = new ByBitmap();
            sources[1].buffer = null;
            sources[1].ScanLine = null;
ScannerIDnative.SavePicToStream(ref sources,IDcardMode)
}





我完成的结构工作,可以有人帮忙吗?



我的尝试:





The struct that i done dosent work, can anyone help?

What I have tried:

public struct ByBitmap
   {

       public int biWidth;
       public int biHeight;
       public int biBitCount;
       public int bfSize;
       public int BytesPerLine;
       public byte[] ScanLine;
       public byte[] buffer;
   }

推荐答案

你的struct的int类型应该可以正常工作,但对于byte []你必须在运行时的CSharp 中分配缓冲区。为此你必须知道这些值的所需大小并在之前进行调用。



另一种方法是从C ++获取字节缓冲区并且制作一个在C#中复制



看看我的文章及其代码,特别是在函数buildBuffer及其用法中。
The int types of your struct should work correctly, but for the byte[] you must allocate buffer in the runtime of CSharp. For that you must know the needed size of these values and make that call before.

The other way is to get the bytes buffers from C++ and make a copy in C#.

Take a look at my article and its code specially at the function buildBuffer and its usage.


这篇关于如何将C ++结构转换为C#结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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