我正在使用c ++ - cli生成一个dll。 dll中的类看起来像这样:
ref class Locator
{
public:
Locator(int HP) : m_HP(HP) { }
~Locator()
{ }
Dictionary<String^, array< Byte >^>^ Locate(Dictionary<String^, String^>^ imgParms)
{ ..... }
private:
int m_HP;
如何公开它以在c#中使用它?该类和成员未在c#
中公开答案 0 :(得分:4)
您需要使用public
关键字使托管类型对程序集的使用者可见。尝试
public ref class Locator { ... };
答案 1 :(得分:0)
几个月前我问过一个类似问题的问题:
How to use a C callback from C#?
以下是我对该问题的回答中的一些额外提示:
Calling C++ DLL from C++ works, but not from C#
我读到你正在使用OpenCV,你知道Emgu CV: OpenCV in .NET (C#, VB, C++ and more)吗? : - )
答案 2 :(得分:-1)
C ++ / CLI生成标准的.NET托管程序集。这就是C ++ / CLI =&gt;的重点。将现有C ++代码编译到托管程序集中,而不将其重写为CLS语言。
因此,只需将此程序集引用为您的使用项目中的任何其他.NET程序集。然后消费:
var imgParms = new Dictionary<string, string> { { "foo", "bar" }, { "baz", "bazinga" } };
var locator = new Locator(123);
var result = locator.Locate(imgParams);
// TODO: do something with the result dictionary