Jump to content

Calling GetValueByPointer.xnode in executable


Recommended Posts

I've got a 3rd party DLL I call from within my application.  One of the functions returns a pointer to a variable length null terminated string.  I use the mysterious GetValueByPointer.xnode to dereference the string and return it's value.  This works great from within the Labview development environment.  I'm using 2013Sp1.

 

But when I compile the application into an executable, the xnode returns an error 7.  It appears the DLL is returning a valid pointer, but the xnode can't dereference it.  My hunch is that the pointer is crossing some kind of protected boundary, but I don't know for sure.

 

I suppose I could write a wrapper around the DLL call, but I really don't want to have to do that if there is a simple workaround.  Any ideas?

 

post-7727-0-17278600-1412865153_thumb.jp

Edited by EricLarsen
Link to comment

If that parameter is a string, why not just configure it as a string in the Call Library Function Node setup? Strings are always passed by pointer, and LabVIEW knows how to deal with it. Also, I assume you know what the maximum string length is. You should preallocate memory for that string, and pass it in on the input side. You can preallocate a string by initializing an array of U8 to the correct size, then converting the byte array to a string. Or, you can set the string length in the Call Library Function Node setup.

Link to comment
 

I've never tried it but I think there is a LabVIEW.exe call that can do this called MoveBlock

 

 

MoveBlock would work if you knew the string length in advance.  I don't think you could use it for a variable length string.  The xnode is supposed to have some internal magic that handles strings, and it does work.  Just not in a compiled executable.

 

If that parameter is a string, why not just configure it as a string in the Call Library Function Node setup?

 

Sounds promising, but it doesn't appear to work.  Labview interprets this as a 3 or 4 byte gibberish string.  I'm trying to wrap my head around why this is.

Link to comment

Odd. Another option is to treat it as an array of U8 instead of a string. Again you'll need to allocate enough space for it initially. Then you can convert from U8 to string yourself.

 

Can you share your code where you configure the parameter as a string, and also the prototype for the function you're calling? I assume you've set that parameter to be a C string.

Link to comment

Darin, you're a genius.  I was barking up the wrong tree.  Error 7 is a file not found error, which often seems like one of those generic error codes that's thrown out when nothing else will do.  But no, in this case the error means exactly what it says, it couldn't find the library specified on the diagram.  Problem fixed!

Link to comment
  • 7 months later...

I've got a 3rd party DLL I call from within my application.  One of the functions returns a pointer to a variable length null terminated string.  I use the mysterious GetValueByPointer.xnode to dereference the string and return it's value.  This works great from within the Labview development environment.  I'm using 2013Sp1.

 

But when I compile the application into an executable, the xnode returns an error 7.  It appears the DLL is returning a valid pointer, but the xnode can't dereference it.  My hunch is that the pointer is crossing some kind of protected boundary, but I don't know for sure.

 

I suppose I could write a wrapper around the DLL call, but I really don't want to have to do that if there is a simple workaround.  Any ideas?

 

attachicon.gifxnode.jpg

 

This appears to probably call libtiff and there the function TIFFGetField() for one of the string tags. This would return a pointer to a character string and as such can indeed not be directly configured in the LabVIEW Call Library Node. The libtiff documentation is not clear about if the returned memory should be deallocated explicitedly afterwards or if it is managed by libtiff and properly deallocated when you close the handle. Most likely if it doesn't mention it, the second is true, but definitely something to keep in mind or otherwise you might create deep memory leaks!

 

As to the task of returning the string information in that pointer there are in fact many solutions to the problem. Attached VI snipped shows two of them.

 

"LabVIEW Manager" calls a LabVIEW manager function very much like the ominous MoveBlock() function and has the advantage that it does not require any extra DLL than what is already present in the LabVIEW runtime itself.

 

"Windows API" calls similar Windows API functions instead.

 

post-349-0-93677900-1432624699_thumb.png

  • Like 2
Link to comment
  • 3 years later...
On 10/9/2014 at 0:24 PM, Darin said:

The XNode uses a CLFN with the library wired by path.  I have used this CLFN inside an executable, see if it works for you.

 

GetStringFromPointer.png

Could someone please convert this snippet to a .vi format here? 

I'm using LV-2016 and dropping this snippet in BD imports as simple PNG image. I hope if it's converted to .vi in LV2012, I can use it in LV2016.   

Link to comment

Nope sorry. Somewhere between transfering that image to the LAVA servers and then back to my computer something seems to have santized the PNG image and removed the LabVIEW specific tag. The image I got onto my computer really only contains PNG data without any custom tags. The same thing seems to happen with the snippet from my last post.

I suspect something in Lava doing some "smart" sanetizing when downloading known file formats, but can't exclude the possibility of a company firewall doing its "smarts" transparently in the background.

Hope that Michael can take a look in this if snippets have been getting sanitized on Lava or if it is something in our browsers or network.

I attached a simplified version of my VI for you.

C String Pointer to String.vi

Edited by rolfk
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.