Cipher
Cipher

Reputation: 6102

Send a string from C# to C++

I have a C++ program which does some processing on a char search[500] array. The dodge here is that the search[] has to be assigned value from C# program.

Consider, that I have this C# program which gets user's input from textbox and have to send this string to C#.

I have been able to export the data, functions and variables from C++ to C#, but I am not familiar how the reverse is done.

[DllImport("Test.dll", EntryPoint = "fnmain", CallingConvention = CallingConvention.Cdecl , CharSet = CharSet.Ansi)]
private static extern int fnmain();//pass what in parameter?

C++

//search[] parameter has to be here. What type to be assigned to get from C# and further get search[] char array
    int main(char search[])
    {
    ..
    }

Upvotes: 1

Views: 202

Answers (2)

Akshaya Shanbhogue
Akshaya Shanbhogue

Reputation: 1448

This may sound silly. Have you considered calling C++ program with command line arguments? If initialization takes a lot of time, you can use concepts of pipes or read/write from or to files. If you can do a little bit of socket programming, that would mean true asynchronous passing of data. Hope this helped.

Upvotes: 0

zmbq
zmbq

Reputation: 39059

I think you want search to be a string. I believe CharSet.Ansi is all you need to make sure the interop converts strings to char *.

Upvotes: 1

Related Questions