how to call a C# function, foo(out byte )? -- help passing a byte pointer
27 views (last 30 days)
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:
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'.
Friedrich on 21 Jul 2014
Edited: Friedrich on 22 Jul 2014
have you tried calling it like this
[bool_val, byte_array] = obj.GetLatestBuffer();
This works fine for me in 14a with the following example
public bool GetLatestBuffer(out byte Buffer)
Buffer = new byte;
for (int i = 0; i < 10;i++)
Buffer[i] = (byte)i;
>> a = ClassLibrary1.Class1
Class1 with no properties.
>> [bool,array] = a.GetLatestBuffer()
Byte with properties:
SyncRoot: [1x1 System.Byte]
SideNote: The out keyword forces the routine GetLatestBuffer to assign Buffer to some value. So you do NOT need to pass down a preallocated array and since you dont need to do this it appears as output in MATLAB directly.
Also in C# when using OUT you never pass down a preallocated array. So what MATLAB does is correct here and matches the .NET programming.
More Answers (2)
James Tursa on 5 Jun 2014
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);