title: Matlab C-DLL, char* type to send image data truncated
body: <p>I am using loadlibrary to interface with a DLL that returns image data in a struct containing info about the size of the image and a field where the actual image data is stored:</p>
  
  <pre><code>struct ImageStruct
  {
      // vertical size of the image [pixel]
      int imageHeight;
  
      // horizontal size of the image [pixel]
      int imageWidth;
  
      // image data size [byte]
      int imageSize;
  
      // pointer to image data
      char * imageBuffer;
  };
  </code></pre>
  
  <p>Matlab turns that into the following statement in the proto file:</p>
  
  <pre><code>structs.ImageStruct.members=struct('imageHeight', 'int32', 'imageWidth', 'int32', 'imageSize', 'int32', 'imageBuffer', 'cstring');
  </code></pre>
  
  <p>I then instantiate such a struct using <code>str = libstruct('ImageStruct',[]) % default initialized</code> and pass it, through <code>calllib</code> to a C function which takes a pointer to such a struct and fills it with image data. The problem is that my image data can contain zeros. Matlab automatically turns the char* member into a char array, stopping at the first 0 it encounters. This means my image data gets truncated. I however know how many values there are, this is returned in the imageSize member. How do I access the whole array?</p>
  
  <p>I have found one solution, changing the type of the <code>imageBuffer</code> member in the proto file to <code>uint8Ptr</code> and then telling matlab what number of elements should be read from the pointer:</p>
  
  <pre><code>str.imageBuffer.setdatatype(str.imageBuffer.DataType,1,str.imageSize);
  </code></pre>
  
  <p>Is there a better solution?</p>