charlie87 Posted August 20, 2014 Report Share Posted August 20, 2014 There is nothing new there as far as iterating the array of strings goes. Instead of a double array you basically have a string. This is a C string in the DLL and you need to MoveBlock() into a LabVIEW handle that you have allocated before with a long enough size. Using Initialize Array with a type of U8 and passing it as C array pointer into the dst parameter of MoveBlock() will do, and after the MoveBlock() call you can convert it to a string with Bytes To String. Thank you for answer. I worked it out exactly as you described. However, is there any option to do it without the string preallocation ? My C DLL function serialize some results and the the final length of the returned string is unknown.... Quote Link to comment
Rolf Kalbermatter Posted August 20, 2014 Report Share Posted August 20, 2014 Thank you for answer. I worked it out exactly as you described. However, is there any option to do it without the string preallocation ? My C DLL function serialize some results and the the final length of the returned string is unknown.... It sure is known when the function returns. So you would need to determine its length after the function returned the array of strings. There is a C runtime function strlen() which does exactly that, and a LabVIEW Manager Function StrLen() which does the same. So calling StrLen() with the CLN just like you did with MoveBlock() on the string pointer will return you the number of characters in the string and then you can do an Initialize Array with that length and then a MoveBlock() to copy the string from the string pointer into the LabVIEW byte array and then convert it with Bytes to String into a String. There is another LabVIEW Manager function LStrPrintf() which combines those two into one convinient function call. The definition is: MgErr LStrPrintf(LStrHandle handle, CStr format, .....); You would configure the first parameter of the CLN as LabVIEW String handle passed by value, the second as C String pointer, and the third as Pointer sized integer. To the first you wire an empty LabVIEW string constant, to the second a string constant containing "%s" (without quotes) and the third is your C string pointer from your array. The output of the first parameter then contains the properly sized string. The return value of the function is an int32 and if not equal to zero indicates a LabVIEW error code. 1 Quote Link to comment
cuoredibue Posted September 8, 2015 Report Share Posted September 8, 2015 Hi, I am new here, and new with LV. I am developing a project with LabView 2013 SP1 f5 32bit. On windows 7 and windows 8.1. From my LabView application I need to call a VLC dll library for streaming of a video. VLC is open source and written in C. The first function I need to use has this prototype. libvlc_instance_t * libvlc_new(int argc, int const char *const * argv); And I need to call it with this ‘C’ parameters libvlc_new(0, NULL); It looks simple but I am having headaches with this. This function should return a pointer to the new created instance, but calling libvlc_new() from LV using “call library function†VI returns NULL instead of a valid pointer, which means that an error occurred, therefore the call library function generate error 1097. I placed the libvlc.dll, which contains the funtion libvlc_new(), and the related libvlccore.dll inside the data folder of the project as you can see in the attachment. Also the mp4 file to play is in the data folder. I read on the community forum of LV that I need to create a wrapper in order to pass to a C function an array of pointers (to const char). I tried to do it but it doesn’t work I don’t understand how to create the wrapper to the libvlc_new() function. There are many different opinions and strategy about this on the web, so I feel confused. I just need to call the libvlc_new() with this parameters: libvlc_new(0, NULL). I tried many different option for the parameter setting and also tried the Ned’s solution, but unfortunately it didn’t work for me. Can anyone give me an example about this? Attached you can find the VI that I wrote and that is NOT working. On this VI I am not using any wrapper. Calling 'C style' argv argc from LabView.zip Quote Link to comment
ned Posted September 8, 2015 Report Share Posted September 8, 2015 I haven't opened your VI - I'm still on LV2012 - but for the specific set of arguments 0,NULL you just need to pass two zeroes, both passed by value. Very easy. The first should be configured as an I32, the second as a pointer-sized integer (again, passed by value). No need to mess with arrays. Quote Link to comment
ShaunR Posted September 8, 2015 Report Share Posted September 8, 2015 libvlc-new-always-return-null Quote Link to comment
Rolf Kalbermatter Posted September 8, 2015 Report Share Posted September 8, 2015 I placed the libvlc.dll, which contains the funtion libvlc_new(), and the related libvlccore.dll inside the data folder of the project as you can see in the attachment. Also the mp4 file to play is in the data folder. This is probably one of your problems. DLLs that are directly called from LabVIEW VIs can be confiigured to be moved in any folder by the Application Builder (default is the "data" folder) as the Application Builder will adjust the library path in the Call Library Node to point to that location, when building the application. However secondary dependencies are not resolved by LabVIEW but either by Windows or very seldom by the DLL explicitedly. Windows knows absolutely nothing about a "data" folder and will NOT search in there for DLLs unless you happen to add that directory to the PATH environment variable. But that is not a good solution to do anyhow. Instead you need to move these secondary DLLs into the the same directory as where you executable is. This is always the first directory Windows will search when asked to load a DLL. I usually modify the Application Builder script to install all DLLs into the main directory instead of into a seperate data subdirectory. Quote Link to comment
cuoredibue Posted September 10, 2015 Report Share Posted September 10, 2015 Thanks to rolfk, ShaunR and ned. Now I have the VLC DLL called libvlccore.dll and libvlc.dll inside the root folder of my project, as you can see from the screenshot. Also the plugin folder of VLC has beed copied inside the root folder of my project. I call the dll from the "Call library function" using for argv a pointer-sized integer, passed as value. And I pass to it a zero. As you can see from the screenshot. I still get error 1097 from the call. Also using Labview2013 IDE. - About the "library name or path" text box in the "Call Library Function" I tried to set the value: * Just with the dll name, as you can see in the screenshot. Not working. Error 1097. * Writing the complete path of the project's root folder, where the dll stays. Not working. Error 1097. * selecting "Specify path on diagram" and adding a wire with the path of the root folder. where the dll stays. And again I get error 1097. Your advice seems to be wise to me, but I am still confused by this unexpected behaviour. Screenshot LibVLC call library function.zip Quote Link to comment
Rolf Kalbermatter Posted September 10, 2015 Report Share Posted September 10, 2015 Thanks to rolfk, ShaunR and ned. Now I have the VLC DLL called libvlccore.dll and libvlc.dll inside the root folder of my project, as you can see from the screenshot. Also the plugin folder of VLC has beed copied inside the root folder of my project. I call the dll from the "Call library function" using for argv a pointer-sized integer, passed as value. And I pass to it a zero. As you can see from the screenshot. I still get error 1097 from the call. Also using Labview2013 IDE. - About the "library name or path" text box in the "Call Library Function" I tried to set the value: * Just with the dll name, as you can see in the screenshot. Not working. Error 1097. * Writing the complete path of the project's root folder, where the dll stays. Not working. Error 1097. * selecting "Specify path on diagram" and adding a wire with the path of the root folder. where the dll stays. And again I get error 1097. Your advice seems to be wise to me, but I am still confused by this unexpected behaviour. The project directory is fine for DLLs that you declare by name only inside the Call Library Node. However for Windows the project directory of LabVIEW has absolutely no meaning. LabVIEW tries do load "a.dll" in your project directory which depends on "b.dll" and "c.dll". After LabVIEW attempts to LoadLibrary() with the correct path for "a.dll" everything is out of the hands of LabVIEW and only Windows search path rules apply. That means Windows will not search in the directory where you load your project file from but in the directory where the current executable is located. For a build application this is the directory where your myapp.exe is located but when you work in the LabVIEW IDE then it is in the install directory of LabVIEW itself where labview.exe is located. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.