You can add a C++/CLI class with a function that takes a .NET String
and call the detdata
function. In that method, you can use marshal_as to convert the string. Something like:
#include <string>
#include <msclr\marshal_cppstd.h>
using namespace msclr::interop;
void detdata(unsigned char _data[]);
public ref class Class1
{
public:
Class1(void) {}
void f1(System::String^ str)
{
std::string data = marshal_as<std::string>(str);
detdata((unsigned char*)data.c_str());
}
};
Then, you can use the f1
function in your C# code. Something like:
Class1 c1 = new Class1();
c1.f1("Text 1");
c1.f1("Text 2");
c1.f1("Text 3");