0

My .DLL function outputs a C-pointer to a string which I need to dereference. I realized that I need to dereference the pointer twice, and I know there should be a built in function in LabVIEW which does just that. But I can't seem to find it.

yoni
  • 117
  • 3
  • 1
    Isn't it possible to call the DLL with a string, and in the calling configuration insert a **string? – Ton Plomp Dec 16 '13 at 04:48
  • If you're calling your DLL function from LabVIEW, you can instruct LabVIEW to allocate the necessary memory for you. Then your function simply has to copy the data in. This however gets a bit more complicated if you don't know the maximum length of the string. – DaV Dec 24 '13 at 10:41

1 Answers1

0

In my experience, any memory that will exist in LabVIEW needs to be allocated in LabVIEW. So allocate a char buffer in LabVIEW and pass it in as a String and CStr Pointer in the Call Library Function.

Do everything you can in C and toss the results back out into Labview in a CStr.

WARNING: If you memcpy() outside the bounds of the allocated memory, Labview will most likely crash and you won't be able to catch the error. So either use try / catch with secure version of memcpy, over allocate in Labview, or test sizes.

C++:
void TestDLL(char Name[], int SizeOfLabviewMemory){
    char *StringInC = "Hello World!"; 
    int SmallerStringSize = 0;
    if(strlen(StringInC) < SizeOfLabviewMemory){
         SmallerStringSize = strlen(StringInC); 
    }else{
         SmallerStringSize = SizeOfLabviewMemory;
    }

    memcpy(Name, StringInC, SizeOfLabviewMemory);  
}
Austin
  • 1,018
  • 9
  • 20