Passing pointer argument in MATLAB to a C-DLL function foo(char**)

前端 未结 3 762
感情败类
感情败类 2020-12-10 18:20

I am writing a C-DLL to be called from MATLAB. Is it possible to call a function with const char ** parameter? e.g.

void myGetVersion( const ch         


        
3条回答
  •  情书的邮戳
    2020-12-10 18:52

    I could not get @Amro's solution to work (old version of MATLAB?). So, I had to do something a little more creative:

    pstr = libpointer('voidPtr');
    ret = calllib('libversion', 'myGetVersion', pstr);
    % establish the length
    n = 0;
    while n==0 || pstr.Value(n) ~= 0
        n=n+1;
        pstr.setdatatype('uint8Ptr', 1, n);
    end
    % truncate to exclude the NULL character
    pstr.setdatatype('uint8Ptr', 1, n-1);
    % convert to string
    display(char(pstr.Value))
    

提交回复
热议问题