LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass array of string data to LabVIEW from dll

Hi sir

   I want to pass array of two dimensional f string data to LabVIEW from CVI build dll.I have example code VI and DLL for passing one dimensional array of data to LabVIEW.Please make the correction in the code of array of data to pass in LabVIEW

The  prasent CVI Code as shown below

 

 

/* Call Library Source File */

#include "extcode.h"

_declspec(dllexport) void StringTest(char cstr[],char ByteArray[],long ByteArrayLength,LStrHandle lstr);

_declspec(dllexport) void StringTest(char cstr[],char ByteArray[],long ByteArrayLength, LStrHandle lstr)
{
char temp[39] = "I have modified the string in the DLL!";
int templength = 0;
MgErr err;
/* NULL character should be the 26 character in the string (index 25) */
/* Cstr should be cut off in returning to LabVIEW */
/* ByteArray will not be cut off */

/* Modify the LabVIEW String Handle and send it back */
templength = StrLen(temp);
err = DSSetHandleSize(lstr, sizeof(char) * templength + 4);
if(err != noErr)
{
return; /* Memory issue */
}
(*lstr)->cnt = templength;
MoveBlock((&temp),(*lstr)->str, (*lstr)->cnt);
}

 

Its working fine for this single array data.

I have modified Preasent CVI code with mulitiple array data,but not getting the Correct data,Please make correction in CVI as well as VI

attached below.

 

/* Call Library Source File */

#include "extcode.h"

_declspec(dllexport) void StringTest(char cstr[],char ByteArray[],long ByteArrayLength,LStrHandle lstr);

_declspec(dllexport) void StringTest(char cstr[],char ByteArray[],long ByteArrayLength, LStrHandle lstr)
{
char Strings[39][40] = {"one" , "two" , "three , "four" , "five" , "Six', "Seven" ,"Eight" , "Nine" , "ten" }

int templength = 0;
MgErr err;
/* NULL character should be the 26 character in the string (index 25) */
/* Cstr should be cut off in returning to LabVIEW */
/* ByteArray will not be cut off */

/* Modify the LabVIEW String Handle and send it back */

for(i=o;i<=10;i++)
templength = StrLen( Strings[i]);
err = DSSetHandleSize(lstr, sizeof(char) * templength + 4);
if(err != noErr)
{
return; /* Memory issue */
}
(*lstr)->cnt = templength;
MoveBlock((& Strings[i]),(*lstr)->str, (*lstr)->cnt);
}

 

0 Kudos
Message 1 of 2
(3,323 Views)
The structure of a 2D array is very similar to a 1D array. Rather than having one 4-byte count at the beginning of the structure, it has two: one for rows and one for columns. I don't recall off the top of my head the order, but it is documented in the help files -- as is the order of the elements.

The goal is to build a 1D array of U8s that LabVIEW can cast into a 2D array.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 2
(3,305 Views)