开发者

how to call C++ dll function with int& and int* parameters from C#?

开发者 https://www.devze.com 2023-01-04 08:10 出处:网络
My C++ DLL have a function like this: void func1(int& count, int* pValue); this function will determine the \"count\", and put some values into the pValue int array which is the length of \"cou

My C++ DLL have a function like this:

void func1(int& count, int* pValue);

this function will determine the "count", and put some values into the pValue int array which is the length of "count".

how can I define my C# code? you 开发者_StackOverflowcan ignor the [DllImport ...] part.

thanks,


By ref & isn't going to happen as far as I've worked out.

MSDN has the answers you seek

and don't forget to export your function from C++ as extern "C"

According to MSDN: Default marshaling for arrays on the C# side I think you want something like the following

public static extern void func1( 
  out int count, 
  [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] int[] values );

Where SizeParamIndex tells .net which argument will hold the size of the array to be marshaled.

0

精彩评论

暂无评论...
验证码 换一张
取 消