LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read out a LStrHandle in cluster from LabView dll?

I have problems to read out a cluster from a Labview dll. It contains a LStrHandle which seems to be the
problem. Clusters containing no LStrHandle are working
fine.
Can anybody tell me how this might work?
I am using Visual C++ and Labview 6.

Thanks!

PS: For a single string I can tell the application
builder to pass it as a string pointer, but there is
no way to influence a cluster that way, or???
0 Kudos
Message 1 of 4
(3,189 Views)
You can use the LabVIEW-supplied LStrBuf function (see extcode.h, labview.lib) to get a pointer to the actual string data. I believe what you pass to this is a dereferenced LStrHandle; i.e., if your DLL function's cluster contains an LStrHandle called "myString", you'd do something like this (note the asterisk):

MessageBox(NULL, LStrBuf(*myString), "My string", 0L);

See the manual entitled Using External Code in LabVIEW for more details.

On your second question: you're right; with individual strings/arrays, App Builder offers the choice between C string pointers or LabVIEW string handles, but in clusters we are forced to use handles. I ha
ve asked NI to offer a choice inside clusters as well; perhaps if enough of us ask, they may implement this feature.
0 Kudos
Message 2 of 4
(3,189 Views)
I think my description of the problem was to vague.
The problem is I load the DLL with LoadLibrary()function of MFC then ich call the DLL function.
dllfunction(stringIn,&clusterout);

clusterout is defines as TD1 an contains a LStrHandle.

When is start the DLL I see that stringIn arrived in the dll, the VI panels opens.
When I close the VI Panel there should be clusterout filled. And here is the problem, here it crashes.
Following error appears:
Unbehandelte Ausnahme bei 0x30038c8c in DllCom.exe: 0xC0000005: Zugriffsverletzung-Leseposition 0xcccccccc.

I think thats LStrHandle because without String in the cluster I had no problem to get the data out.
0 Kudos
Message 3 of 4
(3,189 Views)
You say that you are closing the front panel manually. Does this mean that the VI is not running to completion? Perhaps that is why there is an Unhandled Exception error. Instead of closing the VI front panel with the mouse (or with the FP.Open property), can you structure your code so that the VI runs and then exits on its own?

There's another way around this issue. Create a new cluster of unsigned 8-bit Numerics: make sure there are as many Numerics as the largest string you will need, plus one (for example, 20 characters for a 19-character string). Call this cluster a 'String20' or something. Take the String out of your old cluster and replace it with a String20. On the block diagram, truncate your string to 19 characters and concaten
ate a null character (String constant with '\' Codes enabled, set to '\00') to the end of it. Wire this result into a String to Byte Array node, and then wire that into an Array to Cluster node (right-click and set Cluster Size to 20). Bundle this result into your main cluster.

Now, when you build your DLL, your TD1 data type should contain a declaration like this: 'TD2 myString;'. You can replace this text with 'unsigned char myString[20];', and you should be able to get this result from the cluster.
0 Kudos
Message 4 of 4
(3,189 Views)