猿问

如何使用指针作为参数在C#中包装C ++ DLL?

我试图从我的C#程序中的C ++ DLL文件中调用某些函数。但是当涉及到指针时,我陷入了困境。有人可以指出我正确的方向吗?


这是带有目标函数的C ++头文件:


#pragma once


#ifdef STCL_DEVICES_DLL

#define STCL_DEVICES_EXPORT extern "C" _declspec(dllexport) 

#else

#define STCL_DEVICES_EXPORT extern "C" _declspec(dllimport)

#endif


enum SD_ERR

{

    SD_ERR_OK = 0,

    SD_ERR_FAIL,

    SD_ERR_DLL_NOT_OPEN,

    SD_ERR_INVALID_DEVICE,  //device with such index doesn't exist

    SD_ERR_FRAME_NOT_SENT,

};


#pragma pack (1)

struct LaserPoint

{

    WORD x;

    WORD y;

    byte colors[6];

};


struct DeviceInfo

{

    DWORD maxScanrate;

    DWORD minScanrate;

    DWORD maxNumOfPoints;

    char type[32];

};


//////////////////////////////////////////////////////////////////////////

///Must be called when starting to use

//////////////////////////////////////////////////////////////////////////

STCL_DEVICES_EXPORT int OpenDll();


//////////////////////////////////////////////////////////////////////////

///Search for .NET devices (Moncha.NET now)

///Must be called after OpenDll, but before CreateDeviceList!

///In pNumOfFoundDevs can return number of found devices (optional)

//////////////////////////////////////////////////////////////////////////

STCL_DEVICES_EXPORT int SearchForNETDevices(DWORD* pNumOfFoundDevs);


//////////////////////////////////////////////////////////////////////////

///All devices will be closed and all resources deleted

//////////////////////////////////////////////////////////////////////////

STCL_DEVICES_EXPORT void CloseDll();


此外,如何处理其他函数参数,例如WCHAR **和structsDeviceInfo和LaserPoint?


红颜莎娜
浏览 136回答 1
1回答
随时随地看视频慕课网APP
我要回答