首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#中怎样定义C++中的类型,该如何处理

2012-04-08 
C#中怎样定义C++中的类型大家好,我有一个C++的结构体和一个函数声明要在C#中定义,但是对C#中类型不是很了

C#中怎样定义C++中的类型
大家好,我有一个C++的结构体和一个函数声明要在C#中定义,但是对C#中类型不是很了解,所以很多C++中的类型不知道怎么去定义,希望大家能帮帮忙!谢谢。结构体在C++中的定义如下所示:
typedef struct TH_PlateIDResult 
{
char license[16];
char color[8];
int nColor;// 车牌颜色
int nType;// 车牌类型
int nConfidence;// 整牌可信度
int nBright;// 亮度评价
int nDirection;//车牌运动方向,0 unknown, 1 left, 2 right, 3 up , 4 down

TH_RECT rcLocation;
const unsigned char *pbyBits;/* 该识别结果对应的图片的缓冲区, 只有当 bOutputSingleFrame = true 时,该指针才有效。
下次识别后,该缓冲区内容被覆盖。调用程序无需释放该缓冲区。
缓冲区大小等于传递进来的图片数据的长度*/
int nTime;
unsigned char nCarBright;//车的亮度
unsigned char nCarColor;//车的颜色
char reserved[100];// 保留
}TH_PlateIDResult;

函数在C++中的声明:

int __stdcall TH_RecogImage(const unsigned char *pbyBits, int nWidth, int nHeight, TH_PlateIDResult *pResult,
int *nResultNum, const TH_RECT *prcRange, TH_PlateIDCfg *pPlateConfig);

[解决办法]
首先对TH_RECT这个结构体声明,楼主没有贴出来,MSDN是这样:
typedef struct _RECT { 
LONG left; 
LONG top; 
LONG right; 
LONG bottom; 
} RECT; 

估计成员是一样,只是名称不同而已!

C# code
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]public struct RECT{  public int left;   public int top;   public int right;   public int bottom; }[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]public struct TH_PlateIDResult{   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]   public string license;   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]   public string color;   public int nColor; // 车牌颜色   public int nType; // 车牌类型   public int nConfidence; // 整牌可信度   public int int nBright; // 亮度评价   public int int nDirection; //车牌运动方向,0 unknown, 1 left, 2 right, 3 up , 4 down   public RECT rcLocation;   public IntPtr pbyBits;   public int nTime;   public  byte nCarBright; //车的亮度   public  byte nCarColor; //车的颜色   [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]   public  string reserved; // 保留}  [ DllImport( "test.dll" ,CharSet = CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]  public static extern int TH_RecogImage(IntPtr pbyBits, int nWidth, int nHeight, ref TH_PlateIDResult  pResult,ref int nResultNum, ref RECT prcRange, ref TH_PlateIDCfg pPlateConfig); 

热点排行