c++ dll takes unsigned char* as paramater and fills it out, how to use in MATLAB

4 views (last 30 days)
I have a function
int Read(int cindx, unsigned char* buffer, int readamount) in a dll
it fills the buffer out with new data, how do I get this data in Matlab
I have been looking all over and seems I can't find it
(looked at libpointer, and char) can't make sense of it)
I have a C++ background
using MATLAB 7.10.0 32bit

Answers (1)

Kaustubha Govind
Kaustubha Govind on 8 Nov 2011
I'm not very familiar with this, but a similar question has been answered here: http://www.mathworks.com/matlabcentral/answers/6198-attempt-to-call-external-dll-function-causing-segmentation-fault
So it seems that you should pre-allocate a char buffer as suggested in that answer:
b = char(zeros(1,1024))
and pass this in place of the char* buffer parameter.
Btw, I don't know how well C++ DLLs work with LOADLIBRARY. As far as I know, LOADLIBRARY uses the LCC compiler to parse the symbols in the DLL to be loaded. Since LCC is a C compiler, it does not handle C++ syntax well. However, judging from your function signature, it looks very C-style, so you might be able to get away with it.
  1 Comment
Kaustubha Govind
Kaustubha Govind on 9 Nov 2011
Update: While answering another question (here: http://www.mathworks.com/matlabcentral/answers/20702-loadlibrary-calls-lcc-by-default), I found that starting in R2011a, LOADLIBRARY picks up the compiler selected using "mex -setup". So you should be able to load C++ DLLs my selecting a C++ compiler.

Sign in to comment.

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!