how to call a C# function, foo(out byte [])? -- help passing a byte pointer
이전 댓글 표시
Been struggling to call the following function in a C# dll:
public bool GetLatestBuffer(out byte[] buffer)
I've allocated the buffer in Matlab and tried various castings with libpointer, but keep getting the result:
No method 'GetLatestBuffer' with matching signature found for class ...
I could write a wrapper in C# that allocates the buffer ... but would rather do the memory management in Matlab.
My pseudocode is basically:
NET.addAssembly(dllLoc)
ls = luma_ns.Luma(initParams);
ls.function1(params) % --> it works passing parameters by value
buf = zeros(10000,'uint8'); % tried uint16, int16, etc.
pbuf = libpointer('uint8Ptr',buf);
ls.GetLatestBuffer(pbuf) % doesn't match the prototype of out byte []
No method 'GetLatestBuffer' with matching signature found for class 'Luma_ns.Luma'.
Thanks!!
채택된 답변
추가 답변 (2개)
James Tursa
2014년 6월 5일
Have you tried changing the header signature to something more friendly to MATLAB, but have the same basic I/O? E.g.,
bool GetLatestBuffer(char *buffer);
댓글 수: 3
daniel rasnow
2014년 6월 6일
James Tursa
2014년 6월 6일
Don't recompile. Just create a new header file off to the side for MATLAB to use. I.e., copy the actual header h file to a new file, modify that new file by changing the signature of the function in question, then use that new header h file for calllib in MATLAB.
Friedrich
2014년 7월 22일
This wont work because that is the .NET interface he is using and not loadlibrary!!!!
Anthony
2014년 7월 17일
Hi,
You can create a byte[] like this:
A = NET.createArray('System.Byte',4).
Then you just have to pass it to your function.
Hope it helps,
Anthony
카테고리
도움말 센터 및 File Exchange에서 .NET Client Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!