<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Assign pointer to array in DLL  using Call library function in LabVIEW</title>
    <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231873#M127361</link>
    <description>Hello Rolf.&lt;BR /&gt;&lt;BR /&gt;I am pretty sound with pointer concepts however situation is as follows. See what can be done.&lt;BR /&gt;&lt;BR /&gt;I have a set of VIs in LV6.1 from a vendor XYZ to support their device.&lt;BR /&gt;VIs do NOT have block diagrams.&lt;BR /&gt;The first VI creates an array (unknown size usually up to 10) and gives it to me.&lt;BR /&gt;The vendor support is DEAD.&lt;BR /&gt;I MUST port VI to 7.0 or to higher version.&lt;BR /&gt;&lt;BR /&gt;To do this, my approach is:&lt;BR /&gt;I am creating DLLs of their 6.1 VIs.&lt;BR /&gt;Will Call the DLLs from 7.1&lt;BR /&gt;&lt;BR /&gt;I have simulated  DLL functionality (which is exactly same as vendor VIs functionality) in DLL VIs I created and have attached.&lt;BR /&gt;&lt;BR /&gt;When I tried to call them thru ‘DummyWrapper.VI’ I hit the problems you saw.&lt;BR /&gt;&lt;BR /&gt;Modifying vendor VIs is out of question.&lt;BR /&gt;&lt;BR /&gt;My question is how can I use them as they are (I realize there will be some memory leakage, but first VI (...Connect.VI) is going to be called only once in several months. I can afford it)  ? Can you suggest? &lt;BR /&gt;&lt;BR /&gt;Is there any other way?&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;Sandeep</description>
    <pubDate>Wed, 22 Jun 2005 16:41:14 GMT</pubDate>
    <dc:creator>TeaAndBiscuits</dc:creator>
    <dc:date>2005-06-22T16:41:14Z</dc:date>
    <item>
      <title>Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231482#M127210</link>
      <description>Please look at  ‘DummyWrapper.VI’&lt;BR /&gt;There is something wrong with implementing ‘Call Library Function1’&lt;BR /&gt;It leads to 2 errors.&lt;BR /&gt;&lt;BR /&gt;I have included VIs which I used to create the DLLs.&lt;BR /&gt;&lt;BR /&gt;Can someone write example code showing correct way to point to an array inside the DLL?&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;Sandeep</description>
      <pubDate>Tue, 21 Jun 2005 22:39:07 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231482#M127210</guid>
      <dc:creator>TeaAndBiscuits</dc:creator>
      <dc:date>2005-06-21T22:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231570#M127247</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Sandeepvd wrote:&lt;BR /&gt;Please look at  ‘DummyWrapper.VI’&lt;BR /&gt;There is something wrong with implementing ‘Call Library Function1’&lt;BR /&gt;It leads to 2 errors.&lt;BR /&gt;&lt;BR /&gt;I have included VIs which I used to create the DLLs.&lt;BR /&gt;&lt;BR /&gt;Can someone write example code showing correct way to point to an array inside the DLL?&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;Sandeep&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You can't do that! In C the caller is supposed to allocate array and string buffers. Here the caller is the DummyWrapper VI. So in order to pass an array to the Connect function you have to allocate it in LabVIEW and pass its pointer to the function. You also have to tell the function in the len parameter how large the array is you allocated, this parameter is not meant for you to receive the length of the array from the function.&lt;BR /&gt;&lt;BR /&gt;Basically you have about everything wrong one can do wrong with calling DLLs, so I think you should first read a text book about C programming, especially the chapter about pointers, before we can go on with this.&lt;BR /&gt;&lt;BR /&gt;Besides USing a Call Library Node to call a LabVIEW DLL is a very complicated and uneffective way of doing business. Also I don't think it is a good starting point to learn about the problems and difficulties of C pointers and their handling.&lt;BR /&gt;&lt;BR /&gt;Rolf Kalbermatter&lt;P&gt;Message Edited by rolfk on &lt;SPAN class="date_text"&gt;06-22-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:32 AM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2005 07:29:59 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231570#M127247</guid>
      <dc:creator>rolfk</dc:creator>
      <dc:date>2005-06-22T07:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231873#M127361</link>
      <description>Hello Rolf.&lt;BR /&gt;&lt;BR /&gt;I am pretty sound with pointer concepts however situation is as follows. See what can be done.&lt;BR /&gt;&lt;BR /&gt;I have a set of VIs in LV6.1 from a vendor XYZ to support their device.&lt;BR /&gt;VIs do NOT have block diagrams.&lt;BR /&gt;The first VI creates an array (unknown size usually up to 10) and gives it to me.&lt;BR /&gt;The vendor support is DEAD.&lt;BR /&gt;I MUST port VI to 7.0 or to higher version.&lt;BR /&gt;&lt;BR /&gt;To do this, my approach is:&lt;BR /&gt;I am creating DLLs of their 6.1 VIs.&lt;BR /&gt;Will Call the DLLs from 7.1&lt;BR /&gt;&lt;BR /&gt;I have simulated  DLL functionality (which is exactly same as vendor VIs functionality) in DLL VIs I created and have attached.&lt;BR /&gt;&lt;BR /&gt;When I tried to call them thru ‘DummyWrapper.VI’ I hit the problems you saw.&lt;BR /&gt;&lt;BR /&gt;Modifying vendor VIs is out of question.&lt;BR /&gt;&lt;BR /&gt;My question is how can I use them as they are (I realize there will be some memory leakage, but first VI (...Connect.VI) is going to be called only once in several months. I can afford it)  ? Can you suggest? &lt;BR /&gt;&lt;BR /&gt;Is there any other way?&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;Sandeep</description>
      <pubDate>Wed, 22 Jun 2005 16:41:14 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/231873#M127361</guid>
      <dc:creator>TeaAndBiscuits</dc:creator>
      <dc:date>2005-06-22T16:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232185#M127506</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Sandeepvd wrote:&lt;BR /&gt;Hello Rolf.&lt;BR /&gt;&lt;BR /&gt;I am pretty sound with pointer concepts however situation is as follows. See what can be done.&lt;BR /&gt;&lt;BR /&gt;I have a set of VIs in LV6.1 from a vendor XYZ to support their device.&lt;BR /&gt;VIs do NOT have block diagrams.&lt;BR /&gt;The first VI creates an array (unknown size usually up to 10) and gives it to me.&lt;BR /&gt;The vendor support is DEAD.&lt;BR /&gt;I MUST port VI to 7.0 or to higher version.&lt;BR /&gt;&lt;BR /&gt;To do this, my approach is:&lt;BR /&gt;I am creating DLLs of their 6.1 VIs.&lt;BR /&gt;Will Call the DLLs from 7.1&lt;BR /&gt;&lt;BR /&gt;I have simulated  DLL functionality (which is exactly same as vendor VIs functionality) in DLL VIs I created and have attached.&lt;BR /&gt;&lt;BR /&gt;When I tried to call them thru ‘DummyWrapper.VI’ I hit the problems you saw.&lt;BR /&gt;&lt;BR /&gt;Modifying vendor VIs is out of question.&lt;BR /&gt;&lt;BR /&gt;My question is how can I use them as they are (I realize there will be some memory leakage, but first VI (...Connect.VI) is going to be called only once in several months. I can afford it)  ? Can you suggest? &lt;BR /&gt;&lt;BR /&gt;Is there any other way?&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;Sandeep&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;You have two options:&lt;BR /&gt;&lt;BR /&gt;1) Configure the array as a pointer to a handle in the DLL build and also call it as such. You won't have any lenght parameter anymore as you get directly the entire array into LabVIEW. This does definitely work if the DLL is the same version as the LabVIEW system it is called from. I'm not quite sure how LabVIEW will deal with it when the DLL is run in a different runtime system than the development system calling it but this probably will create trouble.&lt;BR /&gt;&lt;BR /&gt;2) Or treat the handle as an array pointer. Initialize an array on the LabVIEW diagram level which is large enough for the DLL function to fill in its information, configure this both in the DLL and in the Call Library to be an array passed as C array pointer and in the DLL configure len to be the input AND output length parameter of this array. len will then be passed by reference (as pointer).&lt;BR /&gt;&lt;BR /&gt;Now, wire the intiliaized array to that parameter and the length you have initialized it to, to the len parameter. On return the data will have been copied into the array and len tells you how many elements in the array have been filled in. An Array Resize will crop the array to the real size then.&lt;BR /&gt;Option 1) is tricky and almost certainly won't work right when the DLL is compiled in a different version than the LabVIEW system calling it. Option 2) is the best in terms of compatibility and such.&lt;BR /&gt;&lt;BR /&gt;That all said, relying on a driver which is not supported anymore is a very bad decision. What if you run into a bug (Quite likely if they dropped support and if the connector pane of your dummy VIs is an indication of how this driver is written)? All the work already done would be for nothing!&lt;BR /&gt;&lt;BR /&gt;Rolf Kalbermatter&lt;P&gt;Message Edited by rolfk on &lt;SPAN class="date_text"&gt;06-23-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:44 AM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2005 08:41:55 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232185#M127506</guid>
      <dc:creator>rolfk</dc:creator>
      <dc:date>2005-06-23T08:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232694#M127728</link>
      <description>Hello Rolph.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;Your Replies are valuable. &lt;BR /&gt;And I have a couple of concerns.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Option2 works . I created DLLs around vendor code in LV6.1,  and called them from LV7.1&lt;BR /&gt;&lt;BR /&gt;My concerns are as follows:&lt;BR /&gt;&lt;BR /&gt;assumptions: &lt;BR /&gt;Array size being passed as an input to any DLL, is bigger than the corresponding data size generated inside the DLL (underlying LV6.1 wrapper code)&lt;BR /&gt;There is no inherent memory leakage inside vendor code that is available (which I have no access to but) which has been tested with LV6.1 for 2 years.&lt;BR /&gt;&lt;BR /&gt;#Concern 1&lt;BR /&gt;Variable is being passed as an array data pointer. Since it is being passed by reference theoretically as in C, it should not cause any memory leak. However I am unaware about- how LabVIEW understands that the array pointer being passed as an input is for the data it is going to generate? In short I am not clear (but have to be if I want to se this path) how passing by reference works in the (labview) DLL wrapping a labview code.&lt;BR /&gt;&lt;BR /&gt;#Concern 2&lt;BR /&gt;Do you see any memory leak here ? This is crucial. This is killer.&lt;BR /&gt;(I donot see it as long as passing by reference in your case2 works exactly same as pssing by reference in C. &lt;BR /&gt;If there is some other possibility of memory leak happening I need to know about it.&lt;BR /&gt;&lt;BR /&gt;( In my prev email I mentioned about the ..Connect VI and that a few bytes of memory leakage was acceptable. However it may crush the system , specially with modules getting called at high frequency.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regarding your concerns:&lt;BR /&gt;I absolutely agree with you on an any unseen bug , and trying my best (as a programmer) to make mgmt peruse a safer alternative.&lt;BR /&gt;(A well tested set of version independent DLLs by vendor instead of LabVIEW wrappers distribution code is what I ask for.)&lt;BR /&gt;&lt;BR /&gt;I think if this LV6.1 DLL creation, and it’s use in LV7.1 is perused in project, only hope of safe survival is testing …testing…&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again, Rolph.&lt;BR /&gt;NI people comminicated to me to track the solution on this thread which in my opinion probably is the best anyone (NI + dev zone active users) could suggest for this type of problem.&lt;BR /&gt;&lt;BR /&gt;regards&lt;BR /&gt;Sandeep</description>
      <pubDate>Fri, 24 Jun 2005 00:10:52 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232694#M127728</guid>
      <dc:creator>TeaAndBiscuits</dc:creator>
      <dc:date>2005-06-24T00:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232695#M127729</link>
      <description>Rolf,&lt;BR /&gt;And apology for misspelling your name..Rolf.&lt;BR /&gt;&lt;BR /&gt;Sandeep</description>
      <pubDate>Fri, 24 Jun 2005 00:12:48 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232695#M127729</guid>
      <dc:creator>TeaAndBiscuits</dc:creator>
      <dc:date>2005-06-24T00:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232715#M127739</link>
      <description>hello sandeep,&lt;BR /&gt;i am replying to your question without running the VI since my labview installation has crashed.&lt;BR /&gt;it might be some help to you since i had big problem dealing with char pointer while inerfacing the DLL in LV 7.0.&lt;BR /&gt;when dealing with pointers, you need to make sure that proper memmory is assigned in Call library function node.&lt;BR /&gt; a control and some initail value must be passed to input of node to assign that memmory other wise the system will keep generating exceptions and errors.&lt;BR /&gt;-Salman</description>
      <pubDate>Fri, 24 Jun 2005 03:32:51 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232715#M127739</guid>
      <dc:creator>modestt</dc:creator>
      <dc:date>2005-06-24T03:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232733#M127746</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Sandeepvd wrote:&lt;BR /&gt;My concerns are as follows:&lt;BR /&gt;&lt;BR /&gt;assumptions: &lt;BR /&gt;Array size being passed as an input to any DLL, is bigger than the corresponding data size generated inside the DLL (underlying LV6.1 wrapper code)&lt;BR /&gt;There is no inherent memory leakage inside vendor code that is available (which I have no access to but) which has been tested with LV6.1 for 2 years.&lt;BR /&gt;&lt;BR /&gt;#Concern 1&lt;BR /&gt;Variable is being passed as an array data pointer. Since it is being passed by reference theoretically as in C, it should not cause any memory leak. However I am unaware about- how LabVIEW understands that the array pointer being passed as an input is for the data it is going to generate? In short I am not clear (but have to be if I want to se this path) how passing by reference works in the (labview) DLL wrapping a labview code.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;Basically LabVIEWs Application Builder creates a wrapper C function which does following:&lt;BR /&gt;- Build a VI parameter list from the variables on the stack and execute the VI inside the runtime environment using a private VI server method.&lt;BR /&gt;- Copy the lesser of the two (lenght of its outcoming array or the number in the incoming len variable) into the array pointer.&lt;BR /&gt;- Then if you have configured the len variable to be both an input and output, update the variable in len &lt;BR /&gt;with the actually copied number of elements.&lt;BR /&gt;- Deallocate its own memory handle completely.&lt;BR /&gt;&lt;BR /&gt;So there is no memory leak to be expected unless the DLL wrapper code has a bug, but as far as I know this worked fine in LabVIEW 6.1. LabVIEW string and array pointers work exactly the same as their C counterparts. The caller has to allocate the space and the callee fills it in by copying its data into it. No memory allocation sharing between caller and callee is done and this is the only way to create libraries, which are compatible with more than one single runtime environment and different versions of LabVIEW really are already two different runtime environments.&lt;BR /&gt;&lt;BR /&gt;Rolf Kalbermatter&lt;P&gt;Message Edited by rolfk on &lt;SPAN class="date_text"&gt;06-24-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:51 AM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2005 05:48:44 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/232733#M127746</guid>
      <dc:creator>rolfk</dc:creator>
      <dc:date>2005-06-24T05:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/233056#M127877</link>
      <description>Your point is exactly right, Salman.&lt;BR /&gt;Also in case of type mismatch (signed Vs unsigned int, doubles) one may see memory related errors.&lt;BR /&gt;&lt;BR /&gt;thanks.&lt;BR /&gt;Sandeep</description>
      <pubDate>Fri, 24 Jun 2005 17:54:45 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/233056#M127877</guid>
      <dc:creator>TeaAndBiscuits</dc:creator>
      <dc:date>2005-06-24T17:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/233057#M127878</link>
      <description>Thanks, Rolf.&lt;BR /&gt;I also assume that I can pass a bigger size array safely (without any memory leak) into array pointer input variable, than the size of array data DLL is creating (in fact I must). This is because of of the point as in your mention about deallocation of memory.&lt;BR /&gt;&lt;BR /&gt;regards.&lt;BR /&gt;Sandeep</description>
      <pubDate>Fri, 24 Jun 2005 17:58:14 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/233057#M127878</guid>
      <dc:creator>TeaAndBiscuits</dc:creator>
      <dc:date>2005-06-24T17:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign pointer to array in DLL  using Call library function</title>
      <link>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/233112#M127910</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Sandeepvd wrote:&lt;BR /&gt;Thanks, Rolf.&lt;BR /&gt;I also assume that I can pass a bigger size array safely (without any memory leak) into array pointer input variable, than the size of array data DLL is creating (in fact I must). This is because of of the point as in your mention about deallocation of memory.&lt;BR /&gt;&lt;BR /&gt;regards.&lt;BR /&gt;Sandeep&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Of course. You use in such cases always the biggest to be expected array size. The DLL does nothing with this array other than filling in as much data as it has available. On return the array is still the same length but really contains as many elements as the DLL filled in, with the rest being still the intial value, but since you configured the len parameter to be a return value too, you also know how many elements have been filled in. Now use a Resize Array node in the diagram to resize the array to the size effectively filled in by the DLL. &lt;BR /&gt;&lt;BR /&gt;Rolf Kalbermatter&lt;P&gt;Message Edited by rolfk on &lt;SPAN class="date_text"&gt;06-24-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:10 PM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2005 20:08:24 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW/Assign-pointer-to-array-in-DLL-using-Call-library-function/m-p/233112#M127910</guid>
      <dc:creator>rolfk</dc:creator>
      <dc:date>2005-06-24T20:08:24Z</dc:date>
    </item>
  </channel>
</rss>

