I'm trying to call a function in a C++/CLR dll from a C# dll. -> this is working pretty well.
The issue I'm facing is the parameters which should be passed from C# to the function in C++/CLR are not arriving correctly in C++.
In the end I need to pass an array of strings and some boolean parameters from C# to C++/CLR.
What I have done/tried so far:
My C++/CLR part Looks like this:
__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);
}
My C# (dll-import) part looks like this:
[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);
The function call in C# looks like this:
public void btnshow_Click(object sender, RoutedEventArgs e)
{
IDs.Add("0znBcjLrbFBxuK9yivEUEO");
IDs.Add("0cLtxHLKfA9x58$Mi2DnUp");
Translatehelper(IDs.ToArray(), IFCIDs.Count, _blinking, _highlight, _showOnly, _zoom);
}
IDs is defined like this:
public List<string> IFCIDs = new List<string>();