我在C ++ / CLI中编写了一个Wrapper程序集。现在我想从C#调用C ++ / CLI,但是我得到错误:
Error CS0122 'USBWrapper.setPortDisable(int)' is inaccessible due to its protection level
所以我的.h和.cpp文件如下(使用/ clr开关编译):
.h文件:
// USBFunctionsWrapper.h
#pragma once
#include "C:\Users\admin\Downloads\brainstem_dev_kit_win32_i386_17\brainstem_dev_kit_win32_i386\development\lib\BrainStem2\BrainStem-all.h"
#include "C:\Users\admin\Downloads\brainstem_dev_kit_win32_i386_17\brainstem_dev_kit_win32_i386\development\lib\BrainStem2\aUSBHub2x4.h"
using namespace System;
namespace USBFunctionsWrapper {
public ref class USBWrapper
{
public:
USBWrapper();
~USBWrapper();
aErr setPortDisable(int portNumber);
aErr setPortEnable(int portNumber);
aErr usbSleep(int time);
private:
};
}
.cpp文件:
// This is the main DLL file.
#include "stdafx.h"
#include "USBFunctionsWrapper.h"
#include "C:\Users\admin\Downloads\brainstem_dev_kit_win32_i386_17\brainstem_dev_kit_win32_i386\development\lib\BrainStem2\BrainStem-all.h"
#include "C:\Users\admin\Downloads\brainstem_dev_kit_win32_i386_17\brainstem_dev_kit_win32_i386\development\lib\BrainStem2\aUSBHub2x4.h"
aUSBHub2x4 stem;
aErr err = aErrNone;
USBFunctionsWrapper::USBWrapper::USBWrapper() {
err = stem.linkDiscoverAndConnect(USB);
}
USBFunctionsWrapper::USBWrapper::~USBWrapper() {
err = stem.linkDisconnect();
}
aErr USBFunctionsWrapper::USBWrapper::setPortDisable(int portNumber) {
return stem.usb.setPortDisable(portNumber);
}
aErr USBFunctionsWrapper::USBWrapper::setPortEnable(int portNumber) {
return stem.usb.setPortEnable(portNumber);
}
aErr USBFunctionsWrapper::USBWrapper::usbSleep(int time) {
return aTime_MSSleep(time);
}
我正在调用这些函数的C#文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using USBFunctionsWrapper;
namespace USBPortWrapper
{
public class WrapperClass
{
USBWrapper usb;
public WrapperClass()
{
usb = new USBWrapper();
}
public void setPortEnable(int portNumber)
{
usb.setPortEnable(portNumber);
}
}
}
我在c#代码中收到usb.setPortEnable(portNumber)
函数的错误。
你知道这可能是什么原因吗?