C#从非托管C ++ DLL调用函数

时间:2020-02-01 15:28:53

标签: c# c++ dll unmanaged

我有这个Panini扫描器api(我想用C ++编写),我想从c#应用程序中调用。 PS:我没有此DLL的实现,只有标头和dll文件。 VApiInterface.h文件中的函数声明为

typedef DWORD     ERR_CODE;
typedef ERR_CODE  VAPI_RET_TYPE;


typedef struct _DeviceListStruct
{
  DWORD DeviceType;
  char  DeviceSerialNumber[MVX_SN_SIZE];
  DWORD DeviceID;
  DWORD InternalDeviceID;
  BOOL  Connected;
}DEVICELISTSTRUCT,* PDEVICELISTSTRUCT;

// Tag for VISION API function declaration
#define VISION_API_DECL           __declspec(dllexport)

// VISION API function tag
#define VISION_API                WINAPI
VISION_API_DECL VAPI_RET_TYPE VISION_API VApiGetDeviceList(PDEVICELISTSTRUCT pDevList, DWORD Length, DWORD *DetectedDevices);

我正试图从C#像这样调用此函数

public class VisionAPI
{
    [StructLayout(LayoutKind.Sequential)]
    public struct _DeviceListStruct
    {
        public uint DeviceType;
        [MarshalAs(UnmanagedType.LPStr, SizeConst = 11)]
        public string DeviceSerialNumber;
        public uint DeviceID;
        public uint InternalDeviceID;
        public bool Connected;
    }
    [DllImport("VisionAPI.dll", EntryPoint = "VApiGetDeviceList")]
    public static extern uint VApiGetDeviceList(ref _DeviceListStruct d,uint len,ref uint devices);
}


////////////
//the call

VisionAPI._DeviceListStruct d = new VisionAPI._DeviceListStruct() ;
VisionAPI.VApiGetDeviceList(ref d, 0, 0); 

我收到此错误

Unable to find an entry point named 'VApiGetDeviceList' in DLL 'VisionAPI.dll'.

作为Java后端开发人员,我真的不在这里,我完全不知道我在做什么错。 请帮助。

0 个答案:

没有答案