C#处理C++的的返回值Cbitmap*生成图像在控件中显示

问题描述:

Cbitmap* userGetBitmap(HWND hwnd,int nBMPWIDTH,int nBMPHEIGHT);
hwnd需要显示当前图像的窗口句柄
nBMPWIDTH 需要生成的图像的像素宽度

nBMPHEIGHT需要生成的图像的像素高度

        C++的DLL中有如上函数,请问,用C#如何接招。如何用C#要根据上面的函数生成一个图片并在控件中显示。

Cbitmap* userGetBitmap(HWND hwnd,int nBMPWIDTH,int nBMPHEIGHT);
对于你这个接口:
1,Cbitmap这个是你在C++里定义的,你需要在C#里重新定义一个结构体跟C++的对应;
2,HWND这个可以看一下在C++中他占用几个字节,然后再C#中寻找对应;或者直接在C++中使用,不要再接口中出现;
3,int就不用说了。
给你个参考:
//c++:HANDLE(void ) ---- c#:System.IntPtr

//c++:Byte(unsigned char) ---- c#:System.Byte

//c++:SHORT(short) ---- c#:System.Int16

//c++:WORD(unsigned short) ---- c#:System.UInt16

//c++:INT(int) ---- c#:System.Int16

//c++:INT(int) ---- c#:System.Int32

//c++:UINT(unsigned int) ---- c#:System.UInt16

//c++:UINT(unsigned int) ---- c#:System.UInt32

//c++:LONG(long) ---- c#:System.Int32

//c++:ULONG(unsigned long) ---- c#:System.UInt32

//c++:DWORD(unsigned long) ---- c#:System.UInt32

//c++:DECIMAL ---- c#:System.Decimal

//c++:BOOL(long) ---- c#:System.Boolean

//c++:CHAR(char) ---- c#:System.Char

//c++:LPSTR(char *) ---- c#:System.String

//c++:LPWSTR(wchar_t *) ---- c#:System.String

//c++:LPCSTR(const char *) ---- c#:System.String

//c++:LPCWSTR(const wchar_t *) ---- c#:System.String

//c++:PCAHR(char *) ---- c#:System.String

//c++:BSTR ---- c#:System.String

//c++:FLOAT(float) ---- c#:System.Single

//c++:DOUBLE(double) ---- c#:System.Double

//c++:VARIANT ---- c#:System.Object

//c++:PBYTE(byte *) ---- c#:System.Byte[]

//c++:BSTR ---- c#:StringBuilder

//c++:LPCTSTR ---- c#:StringBuilder

//c++:LPCTSTR ---- c#:string

//c++:LPTSTR ---- c#:[MarshalAs(UnmanagedType.LPTStr)] string

//c++:LPTSTR 输出变量名 ---- c#:StringBuilder 输出变量名

//c++:LPCWSTR ---- c#:IntPtr

//c++:BOOL ---- c#:bool

//c++:HMODULE ---- c#:IntPtr

//c++:HINSTANCE ---- c#:IntPtr

//c++:结构体 ---- c#:public struct 结构体{};

//c++:结构体 *
变量名 ---- c#:out 变量名

//C#中提前申明一个结构体实例化后的变量名

//c++:结构体 &变量名 ---- c#:ref 结构体 变量名

//c++:WORD ---- c#:ushort

//c++:DWORD ---- c#:uint

//c++:DWORD ---- c#:int

//c++:UCHAR ---- c#:int

//c++:UCHAR ---- c#:byte

//c++:UCHAR* ---- c#:string

//c++:UCHAR* ---- c#:IntPtr

//c++:GUID ---- c#:Guid

//c++:Handle ---- c#:IntPtr

//c++:HWND ---- c#:IntPtr

//c++:DWORD ---- c#:int

//c++:COLORREF ---- c#:uint

窗口句柄这种东西,最好不要在C#,跟C++之间传递,你可以传递,int nBMPWIDTH,int nBMPHEIGHT
最好是C++内部自己得到句柄