将 C++ 字符串传递给 C# 函数
Passing C++ string to a c# function
我正在用 c# 包装 Microsoft 的断言 class 并想在 c++ 中使用该代码。我遇到的问题必须处理信息字符串,我不太确定如何将 c++ 字符串传递给 c# 方法。两者都是托管的。
//c# Assert wrapper
static public bool AreEqual<T>(T expected, T actual, string info){
//...
WriteLine(info);
//...
}
从 C++ 调用
//c++
void someCppFunc(){
long expected = 2;
long actual = 2;
Assert::AreEqual<long>(expected, actual, L"Some info message");
}
但是我得到的错误是它没有匹配功能。我该怎么做?
只需将托管字符串传递给它而不是原生 C++ 字符串:
//c++/clr
void someCppFunc(){
long expected = 2;
long actual = 2;
Assert::AreEqual<long>(expected, actual, gcnew System::String(L"Some info message"));
}
我正在用 c# 包装 Microsoft 的断言 class 并想在 c++ 中使用该代码。我遇到的问题必须处理信息字符串,我不太确定如何将 c++ 字符串传递给 c# 方法。两者都是托管的。
//c# Assert wrapper
static public bool AreEqual<T>(T expected, T actual, string info){
//...
WriteLine(info);
//...
}
从 C++ 调用
//c++
void someCppFunc(){
long expected = 2;
long actual = 2;
Assert::AreEqual<long>(expected, actual, L"Some info message");
}
但是我得到的错误是它没有匹配功能。我该怎么做?
只需将托管字符串传递给它而不是原生 C++ 字符串:
//c++/clr
void someCppFunc(){
long expected = 2;
long actual = 2;
Assert::AreEqual<long>(expected, actual, gcnew System::String(L"Some info message"));
}