Last active
October 7, 2024 16:28
-
-
Save j-medland/e3a15f3e21e73c1d3fc8f594356a5ef3 to your computer and use it in GitHub Desktop.
Passing 2d C Array to LabVIEW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#define DLL_EXPORT __declspec(dllexport) | |
int width = 20; | |
int height = 15; | |
unsigned char *data = NULL; | |
void DLL_EXPORT init() | |
{ | |
if (data == NULL) | |
{ | |
data = (char *)malloc(width * height * 3); | |
// write some dummy values into data | |
for(int p =0; p< (height*width*3); ++p){ | |
*(data+p) = (unsigned char)(p%256); | |
} | |
} | |
} | |
void DLL_EXPORT get_RGB_Array(const char *url, unsigned char **RGBarray, int *height_ptr, int *width_ptr) | |
{ | |
*height_ptr = height; | |
*width_ptr = width; | |
*RGBarray = data; | |
} | |
void DLL_EXPORT deinit() | |
{ | |
if(data != NULL){ | |
free(data); | |
data = NULL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is in reference to this stackoverflow question
The labVIEW runtime exports a function called MoveBlock which works like
memcpy
and allows you to copy data from a pointer to another pointer.This means we can copy the data from the pointer provided by
get_RGB_Array()
into a pre-sized labVIEW array.There are other options and you can follow the later sections of these notes to learn about being able to manipulate LabVIEW allocated memory from you C-code in this how-to guide