我对C++不太了解,但是我必须使用.NET来编写一些C++代码。我尝试DLLImport,但我失败了。所以我尝试用C++/CLI来做一个包装。C++/CLI如何翻译此代码?
但我不知道明白了一切......
这是我想要导出的函数(MyFunction的)基本的C + + H文件
extern "C"
{
__declspec(dllexport) IplImage* MyFunction(IplImage *src, std::string* name, OneEnumerationType myEnum, bool myBool, float myFloat);
}
这是包装H代码。
#include "MyFunction.h"; // the file containing the h code
#include <string>
namespace MyWrapper{
public ref class MyWrapperClass {
public:
MyWrapper(){};
IplImage^ GetMyFunction(IplImage *src, std::string^ name, OneEnumerationType myEnum, bool myBool, float myFloat);
}
这是Wrapper cpp代码。
#include "MyWrapperCode.h";
namespace MyWrapper{
IplImage^ MyWrapperClass::GetMyFunction(IplImage* src, std:string^ name, OneEnumerationType myEnum, bool myBool, float myFloat){
MyFunction(src, name, myEnum, myBool, myFloat);
}
}
这是我的问题:
1)当我编译,错误是“‘^:不能用在类型的IplImage这种间接’和相同的消息类型‘的std :: string’ 。 我已经遵循了这一逻辑:
ClasseNative clNat2 = *clNat; --> ClasseManagee clMan2 = *clMan;
ClasseNative &clNat3 = clNat2; --> ClasseManagee %clMan3 = clMan2;
ClasseNative *clNat4 = &clNat2; --> ClasseManagee ^clMan4 = %clMan2;
我所看到的,这是更好地使用系统::字符串我尝试这种方式,但最初的功能是使用的std :: string ......顺便说一句,这是为什么。更换好吗?
2)如何获得MyFunction IplImage结果?直通一个私有成员和得到我想,但我不知道如何初始化它...
3)棘手的问题。是否有可能让CLI在IplImage .NET结构中获得IplImage结构(来自OpenCV库)(我的函数的结果),何时调用我的包装?不知道这个问题是否可以理解...
非常感谢您的帮助。 在这个问题上回顾3天...
谢谢您的回答。 – PetersLast 2013-04-10 14:03:32
所以我需要添加一种System :: String^myVar作为私有变量?又如何将数据从Std :: string传递给System :: String? – PetersLast 2013-04-10 14:05:14
作为参数。 std:string作为函数调用的局部变量。您的托管包装类使用者无法识别本机std:字符串。 – 2013-04-10 17:39:15