我正在尝试从 C# dll 调用 C++/CLR dll 中的函数。-> 这工作得很好。
我面临的问题是应该从 C# 传递到 C++/CLR 中的函数的参数在 C++ 中没有正确到达。
最后,我需要将字符串数组和一些布尔参数从 C# 传递到 C++/CLR。
到目前为止我所做/尝试过的事情:
我的C++/CLR部分看起来像这样:
__declspec(dllexport) void __cdecl BCFConsumer::Translatehelper(char **IDs, int len, bool blinking, bool highlight, bool showOnly, bool zoom){
vector<std::wstring> IDsVec;
std::wstring tmp;
msclr::interop::marshal_context context;
for (int i = 0; i < len; i++) {
IDsVec.push_back(std::wstring(IDs[i], IDs[i] + strlen(IDs[i])));
}
ShowElements(IDsVec, blinking, highlight, showOnly, zoom);
}
我的C#(dll 导入)部分如下所示:
[DllImport("BCF.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?Translatehelper@BCFConsumer@@QEAAXPEAPEADH_N111@Z")]
public static extern void Translatehelper(string[] IDs, int size, bool blinking, bool highlight, bool showOnly, bool zoom);
C# 中的函数调用如下所示:
public void btnshow_Click(object sender, RoutedEventArgs e)
{
IDs.Add("0znBcjLrbFBxuK9yivEUEO");
IDs.Add("0cLtxHLKfA9x58$Mi2DnUp");
Translatehelper(IDs.ToArray(), IFCIDs.Count, _blinking, _highlight, _showOnly, _zoom);
}
ID 定义如下:
public List<string> IFCIDs = new List<string>();