Jump to content

Calling GetValueByPointer.xnode in executable


Go to solution Solved by Darin,

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 post
Share on other sites

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 post
Share on other sites
 

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites
  • 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 post
Share on other sites
  • 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 post
Share on other sites

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 post
Share on other sites

Join the conversation

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

Guest
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.

  • Similar Content

    • By Randy_S
      Good morning,
      I have a DLL I created (in Labview)  that takes in string information, does some magic crunching on it to create a password that is passed out as a string.  This DLL will be called from CVI and probably from a C# application.
      This should be so simple, however I cannot figure out how to pass the string in and get the modified string out of my DLL.
      I've had no luck at all getting this DLL to work by trying many different things.  It crashes LV, returns and error, or simply passes nothing out during my trials.
      I've included the project (its small) in zipped format.  Can one of you kind souls take a look at my code and tell me what I'm doing wrong, or what I need to do correctly to both, configure the DLL and then call it from LabVIEW?
       
      Thank you!
       
      Randy
      Password Generator.7z
    • By Manudelavega
      As far as I now there is 2 way to define how to format a numeric into a string using the floating point representation (%f):
       
      - Setting the number of significant digits (%_2f)
      - Setting the number of digits or precision (%.2f)
       
      However I often find myself in the need of a way to define the width of the string. For example I always want 3 digits maximum. Using significant digits won't work if the number is 0.0012 since this only has 2 significant digits, so the string will be 0.0012 even though I would like to see 0.00 (so 0 if we hide trailing zeros).
       
      On the other hand, using digits of precision won't work if I have a number like 123.45 since it has 2 digits of precision, so the string will be 123.45 even though I would like to see 123.
       
      Now the obvious brutal way would be to use a string subset and only keep the first 3 digits (I guarantee that my number is never bigger than 999). But I really hope there is a more elegant way. I can't imagine that nobody has run into this requirement before. How did you tackle it?
    • By piZviZ
      I am able to read HEX file into Labview using read from Text file..I am getting data into labview in terms of string.
       
      Problem =>  Now i want to load this HEX file into microcontroller using VISA-rs232 .Is it require to further conversion or i can load HEX file(in form of string) directly into microcontroller ?
      rs232.vi
    • By Majo
      Hello, 
      I need a little help. 
      I want to send from LabVIEW to Arduino via serial port the string for example "ABC" and so on. 
      The problem is that when I send the string from LabVIEW .......the Arduino do nothing. Sometimes shows some kind of sign.
      When I send the string via Visual Studio it works perfectly.
      Is there someone who can help me.
       
      I attached picture of vi and Arduino code
       
      Thank you very much.   
       
       

      Arduino code.txt
    • By Dawid
      Hello,
       
      I write here a topic, because I'm looking for a help since I can not deal with some issue for a long time. I'm trying to write LabView program which will program uC flash using JTAG usbWiggler manufactured by Macraigor Systems. The manufacturer provides customers with program to do whole staff connected with programming, but it's stand alone app and I would like to build the programming process into the test sequence performed by LabView (program + test). Additionally the manufacturer provides a library to call various functions related to programming, erasing etc. I tried to write a program to use dll but no success. There is some small cmd exe program which is using the dll (also created by the supplier), and its working, but there are some bugs in it, and I cannot change it or make some error handling so that's why I decided to use dll alone. I attached dll, dll readme file, ocd file (configuration file for uC), and VIs.
      I checked the first command called: "FlashSetupAndConnect" it's working without hardware, so you are able to test something. (checked with cmd exe program, without device it always pass if input data is ok, it fails when something is missing like bad path file etc.) Status from each function should be "1", and I get "0" all the time.
       
      The function should looks like this (copied from readme file):
      int FlashProgrammer_SetupAndConnect(char *ocd_filename, char *device_name, char *device_address, unsigned long baud_rate,
      unsigned long jtag_speed);
       
      I will be very grateful for any answer and advices.
      Dawid K.
      readme.rtf



      OCDandDLLl.zip
×
×
  • Create New...

Important Information

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