C++はC#に文字列を渡します
2446 ワード
方法1: headfile: cpp file C# file
方法2
使用中にエラーが発生したので、さらに検査してから貼り付けます
リファレンス
C#C++dll関数を呼び出すときに文字列を渡すときに注意すべき問題
#pragma once
extern "C" __declspec(dllexport) char* SayHelloWorld();
char* SayHelloWorld(){
return "hello world";
}
[DllImport("persimmon_dll")]
public static extern IntPtr SayHelloWorld();
//
IntPtr ret = SayHelloWorld();
string str = Marshal.PtrToStringAnsi(ret);
方法2
使用中にエラーが発生したので、さらに検査してから貼り付けます
リファレンス
C#C++dll関数を呼び出すときに文字列を渡すときに注意すべき問題