C#从非托管C+调用函数+;动态链接库 我有这个PANI扫描器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#从非托管C+调用函数+;动态链接库 我有这个PANI扫描器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#,c++,dll,unmanaged,C#,C++,Dll,Unmanaged,我试着从c#调用这个函数,就像这样 public class VisionAPI { [StructLayout(LayoutKind.Sequential)] public struct _DeviceListStruct { public uint DeviceType; [MarshalAs(UnmanagedType.LPStr, SizeConst = 11)] public string DeviceSerial

我试着从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后端开发人员,我在这里真的很不适应,我完全不知道自己做错了什么。
plz帮助。

您检查地图文件了吗?方法必须在地图中,c#才能看到入口点。请参阅:映射文件?我不知道在哪里可以找到它。但是在函数的声明中,指定了u declspec(dllexport)。结构声明的可能重复也是错误的。字符串需要一个@GSerg,我只有.h文件,dll已经生成,所以我不知道实现中是否包含
extern
。我在结构定义中的字符串变量中添加了
[marshallas(UnmanagedType.LPStr,SizeConst=11)]
,但它不起作用