LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

get string address pointer

Hi, I want to call User32.dll from LabVIEW. I already found an example that works but I would like to change it a little bit to have access to more functionalities. The DLL function uses a Cluster of pointers address [ie U32 controls] as input. One of the pointer is pointing to a text string (the one I want to use in my case). Thus, I have the String control erady on LV, how can I have its address so I update the corresponding cluster control and then call the DLL? Thanks.
0 Kudos
Message 1 of 7
(6,168 Views)

Hi titi_nicolas,

      I'm pretty sure you can simply pass strings as a C-string pointer, but when in doubt, I convert strings to array of bytes in LabVIEW, and configure the CLF to accept a pointer to the array of U8 ( char *).  Either way, User32 will receive a pointer that it will (correctly) assume is a pointer to a character-string.  If passing as array of U8, don't forget to zero-terminate the string/array.

Cheers!

 

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 2 of 7
(6,138 Views)
No, I can't pass the string as pointer since, in this case, I must pass a Cluster of several U32 (on of the U32 being the pointer to the string).
 
To be more specific it concern this example. I want to set the "lpszTitle control" with the address value of my text string. Then how do I get this address (using LV functions if possible)?
 
Thanks
Message 3 of 7
(6,127 Views)
You will need to work with a fixed string length. If you open the example finder (Help -> Find Examples) and search for "DLL" you will find a very extensive example called (appropriately) "Call DLL" one of the cases that it shows is a cluster that has a string in it. As you can see, the string is a fixed length. For the SHBrowseForFolder function I believe the lpszTitle is limited to 255 characters, but you should check the documentation.

As an aside, I am assuming you're trying to display a dialog to select a folder. I don't usually like to use Express VIs, but you'll find a "File Dialog" Express VI in the File I/O -> Advanced palette which I believe will accomplish the same thing.
0 Kudos
Message 4 of 7
(6,112 Views)
The "File Dialog" Express VI does not do the job properly if we want to browse and select a folder *only*. It is still possible to select a file and click Open... which throw an pop-up window at the user face (with a stupid error message btw).
0 Kudos
Message 5 of 7
(6,106 Views)
There's a .NET based browse folder which maybe suitable

http://forums.lavag.org/Browse-for-Folder-t10100.html&pid=41466&mode=threaded#entry41466


There's also one with the windows api, but I think it's basically the same the same as what your doing

http://forums.lavag.org/Prompt-for-directory-t8678.html&pid=32971&mode=threaded#entry32971
0 Kudos
Message 6 of 7
(6,082 Views)


titi_nicolas wrote:
The "File Dialog" Express VI does not do the job properly if we want to browse and select a folder *only*. It is still possible to select a file and click Open... which throw an pop-up window at the user face (with a stupid error message btw).



Hi nicolas,
      I agree - it seems silly for the dialog to show files - and complain - after specifying "Folder Only" - but there's a simple workaround - just supply an unlikely file-pattern, like "!.!"  - then files won't be displayed (so can't be selected!)
 
      I was confused by your original post because you said "The DLL function uses a Cluster of pointers".  The DLL may want a data-type that represents a collection of pointers, but the right name for that datatype isn't a "Cluster".  The right name will be determined by the language the DLL was compiled in - usually "C"/C++ which means the DLL function uses a "structure", or an array.  (Yes, LabVIEW can build DLLs, but then there couldn't be a Cluster of pointers.)
 
      There may be a more elegant way, but the way I build structures for DLLs is to "pack" an array with bytes in the order required by the DLL/structure.  The tricky part here is: LabVIEW doesn't have pointers - so how can you pass the string's address?  I don't know the trick to get the address of (pointer to) a string - but I wouldn't give up.  Maybe there's some User32 function - or .NET function that can be exploited for this.  Worst case, if your have a compiler handy, you could build a DLL to accept a "cstr" parameter and pass the address back as a U32.  Again, if you go down this road, make sure to zero-terminate the string!  And, all this is assuming you're not writing to the string, if so then you'll need to pre-allocate the string-buffer's max-size in LabVIEW.
 
Cheers!
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 7 of 7
(6,066 Views)