How to call a DllImport function with String param?

W

wc

My C# program imported a dll which has a funcation takes a string parameter.

extern "C" __declspec(dllexport) bool __stdcall kickerOpen(string tmpStr)
// in .cpp

How can i call this funcation in C# to pass in the correct string format?
Since string in C# (System.string) is different than string in C++
(std::String).

In my C# code, I'll get a string from user input in textbox (textbox::Text).
private void openbtn_Click(object sender, EventArgs e)
{
string idstr = idStrtxt.Text;
bool isCaseOpen = false;
isCaseOpen = kickerOpen(...); // how?
}

Can anyone advice?

/wc
 
A

Arne Vajhøj

wc said:
My C# program imported a dll which has a funcation takes a string parameter.

extern "C" __declspec(dllexport) bool __stdcall kickerOpen(string tmpStr)
// in .cpp

How can i call this funcation in C# to pass in the correct string format?
Since string in C# (System.string) is different than string in C++
(std::String).

You mean std::string ?

AFAIK you can't.

Change the API to be char*.

Or write some C++ that converts from System::String to std::string
and put it in between.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top