Monday, 26 August 2013

C++ passing string into C# dll

C++ passing string into C# dll

I have a C++ application calling WORD(name,cpu) function in C# dll via
wrapper.cpp and it contain an error. Can anyone help me? Thanks in
advance.
error C2664: 'CsharpDLL::WORD' : cannot convert parameter 1 from
'std::string' to 'System::String ^'
C++ application
extern "C" _declspec(dllimport) void _stdcall WORD(string name, string cpu);
int main()
{
string name="f";
string cpu="F";
WORD(name,cpu);
}
wrapper.cpp
extern "C" _declspec(dllexport) void _stdcall WORD(string name ,string cpu)
{
return CsharpDLL::WORD(name,cpu); // <-- Error here
}
C# dll
public class CsharpDLL
{
public static void WORD(string name, string cpu)
{
if(cpu=="add")
{
Console.WriteLine("aa");
}
}

No comments:

Post a Comment