我在我的C++代碼將數據發送到非託管代碼的DllImport
extern "C" __declspec(dllexport) void*__cdecl
widgetCreate(char* data, size_t length){
return new Widget(data);
}
以下簽名而在我的C#代碼如下:
[DllImport(Path, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr widgetCreate(byte[] data, int length);
我想要的C++代碼,以保持自己的在data
的副本,所以我做了memcpy()
:
extern "C" __declspec(dllexport) void*__cdecl
widgetCreate(char* data, size_t length){
auto copy = new char[length];
memcpy(copy, data, length);
return new Widget(copy);
}
有沒有辦法使火星哈勒爲我做這個副本?像下面這樣的東西?
[DllImport(Path, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr widgetCreate([CopyThisThing] byte[] data);
好的,謝謝你的照明說明。 – Gleno