把C#的委托给C,这个可以正常,但是C想要通过这个委托拿到C#的字符串值 要怎么做?
C#
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void GetStrCallback(StringBuilder str);
[DllImport("...")]
public extern static void SetStrCallback(GetStrCallback cb);
...
public static void Handle(StringBuilder str)
{
str.Append("AAAAAA");
}
SetStrCallback(Handle);
C
typedef void(__stdcall * GetStrCallback)(const char* str);
GetStrCallback _getStrFunc = NULL;
extern __declspec(dllexport) void SetStrCallback(GetStrCallback cb)
{
_getStrFunc = cb;
}
...
void GetCSharpStr()
{
char temStr[1024] = "";
_getStrFunc(temStr);
// 调用C#的函数,但是temStr还是空的,咋整?
}