Rolf <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > znakeeye wrote: > > Hi! > > > > I have made a DLL in C++/MFC. I have to implement a function that can > > fill a LabView 2D-array with some data. How can that be done? > > > > I suppose the function should look something like this: > > int MyDllFunction(unsigned char **matrix, int width, int height) > > { > > for (int r = 0; r < height; r++) > > { > > for (int c = 0; c < width; c++) > > matrix[r][c] = SomeData(r, c); > > } > > > > return 1; > > } > > int MyDllFunction(unsigned char *matrix, int width, int height) > > In fact this is what LabVIEW will generate to be passed to the DLL for a > two dimensional uInt8 array and your function will have to look like this: > > int MyDllFunction(unsigned char *matrix, int width, int height) > { > for (int r = 0; r < height; r++) > { > for (int c = 0; c < width; c++) > matrix[r * width + c] = SomeData(r, c); > } > > return 1; > } > > Two dimensional arrays in C are a little underspecified. Some see it as > a single pointer with column * row elements, others as a pointer to an > array of pointers. LabVIEW chooses for the first! > > > Where should the memory of the array be declared? Maybe LabView can > > allocate the memory itself and pass the function a char-array > > (together with the width and height) to my function? How does it work? > > The memory should always be allocated by the caller, e.g. LabVIEW in > this case. Just use an Initialize Array function to allocate the 2 > dimensional array before passing it to the Call Library Function. > > Rolf K
So basically my function is valid (although I have to switch rows and columns for a valid result) and all I need is to make a LabView program that allocates a 2d-array and passes it to this dll function? Thanks for the information regarding rows and columns. /Chris