LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get CString from a DLL into LabVIEW

Hay guys, I seem to have hit a bit of a brick wall and could do with some help...

The problem is this:  I am currently writing a DLL in VC++, the purpose of which is to get data from a number of C++ classes (which I may add I'm not allowed to alter) and send the resulting data to LabVIEW.  The same classes also deal with data flow the other way, but we wont worry about that because I have them working fine from labview.  I have all of the numeric data comming into labview sucsessfully in the form of a cluster (aka a struct on the C++ side of things), however I can't for the life of me figure out how to get the three CStrings into labview.

Now, you will have to forgive me, as I'm still a novice programmer (only been coding a couple of years now) and this is the first time I've tried to get C++ and G to talk to oneanother.  On my searches, I've found a few things that look like they should be usefull, but dont seem to have worked in this case.  It appears that there are several ways of doing this, but I can't seem to find a complete example to work from (ie i can find examples for the C side, and examples for the G side, but not both together)  The best I could find is this:
http://forums.ni.com/ni/board/message?board.id=170&message.id=30585&query.id=95730#M30585
But the example links are dead-and-burried, and I must confess the explanation is a bit above my head.  Most the other examples I've found are aimed at sending a string FROM labview TO a DLL, which is the opposite of what I'm trying to do.

So what I'm asking for is a link to a good example of what I need to do both on the C side and the G side of things to get LabVIEW to take a CString from a DLL.  I'm not able to alter the CString at its root, however there is nothing stopping me performing some kind of conversion once it enters the DLL wrapper.  I say this because on my travels I've picked up the fact that C and G treat arrays differently (and CString being effectively an array of chars, I'm guessing that applies somewhere along the line here).  If I understand correctly, C sticks a \0 null terminator at the end of the array, whereas G defines the array length as the 1st elliment...

Anyway, some help, advice and links would be greatly appreciated.  Cheers guys.

~Andy~
0 Kudos
Message 1 of 2
(3,903 Views)
EDIT:  Actually, nvm - I figured it out with a bit of lateral thinking lol 😛  It turned out that I hadn't initialized the array in LabVIEW...  pretty silly of me eh?  Anyway its sorted now.  For anyone else who has similar issues -

In LabVIEW, your CallFunctionNode should be set as an array, of type 8 bit signed (should be an Array data pointer).  You then need an actual array (again of 8 bit signed) and you need to initialize it so that it matches (or exceeds) the size of the CString array in your DLL.  You then need to create 2 local variables from that array, change one to read, the other to write, and hook them to the input/output (respectivly) of the Function Node's parameter that relates to your array.

On the C side of things, your function should be laid out the same as the prototype that labview gave you (probably something along the lines of 'void MyDLLFunction(char* MyArray)' )   This passes a pointer to the array, so you can now directly access it as though it was a normal C array, IE you can define/call each array elliment using 'MyArray[x] = 'y'; ' etc.  This can be used in a for loop to map each of the chars from the CString into the array, and it will be returned into LabVIEW.

After this, you need to 'tap off' the line comming out of your call function node in labview, place a 'Byte Array to String' converter on it and send that to your string indicator (or wherever you want the string to go), and thats all there is to it.

I knew it would be a simple answer lol 😛  guess I'm having a blonde day XD  Peace out guys.  No doubt I'll be back in 5 mins askin more questions lol 😛
0 Kudos
Message 2 of 2
(3,895 Views)