Calling a C++ dll with unsigned char* parameters

unsigned char*  等价 BYTE*

例1:

C++:

int __stdcall LIVESCAN_GetFPRawData(int nChannel, unsigned char *pRawData);


C#

[DllImport("GALS1701.dll", EntryPoint = "LIVESCAN_GetFPRawData", CallingConvention = CallingConvention.Cdecl)]
unsafe public static extern int GetFPRawData(int nChannel, byte* pRawData);
unsafe
{
    Byte[] bytes = new Byte[400 * 400 + 1078];
    //就是固定“fixed 语句禁止垃圾回收器重定位可移动的变量”
    fixed (byte* array = bytes)
    {
        Livescan.GetFPRawData(0, array);
    }
}

 例2:

C++

extern "C" _declspec(dllexport) int Auto_Capture(BYTE *pBmpData)

C#

[DllImport("LivescanDll.dll", EntryPoint = "Auto_Capture", CallingConvention = CallingConvention.Cdecl)]
public static extern int Auto_Capture(Byte[] pBmpData);
Byte[] bytes = new Byte[400 * 400 + 1078];
int result = Livescan.Auto_Capture(bytes);

 

posted @ 2013-06-21 17:16  扑通  阅读(500)  评论(0编辑  收藏  举报