<?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: How to create  a structure pointer DLL using Call Library Function Node in LabVIEW</title>
    <link>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/924232#M415366</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;falkpl wrote: &lt;BR /&gt;&lt;P&gt;Sorry I havent passed a struct to a dll in a while.&amp;nbsp; Now that I look as my old code I have a struct as a preallocated Byte array.&amp;nbsp; I then did simple pointer math to get the offsets of the struct fields (assuming fixed sized fields).&amp;nbsp;There is also the import shared library tool if you have the header files but I have not tried this.&amp;nbsp; I remember it being mentioned at ni week that there was a feature for autowrapping dlls with this wizard.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt; The library import wizard is a tool not a magic wand. It can ease import of fairly basic DLL interfaces (the part which is tedious mechanical work) but it can not solve complicated C datatypes and pointer constructs eventhough it does attempt to do some of that too. But C is such a loosely defined language in that respect that one can not possibly think of all possibilities in which pointers and C datatypes can be mixed up by programmers to the point that no automated tool is able to translate it into a fixed typed language like LabVIEW.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add to that that LabVIEW has not really an internal concept of pointers and especially function pointers and the whole exercise to translate some complicated APIs is in vain. While function pointers are simply to difficult to really implement in LabVIEW directly you can trick with complicated data pointer constructs by using rather complicated techniques in the LabVIEW diagram.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the function wants to get passed or probably more likely will return in a pointer a pointer array of array pointers! Anyone still with me after this sentence? Whoever has trouble to understand the implications of this sentence I would suggest to move on and try another exercise. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://ni.lithium.com/i/smilies/16x16_smiley-happy.gif" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For those still following, the C prototype in the header file does not specify many aspects of this at all. This must be determined from the manual, the context of the API, other C sample code using that function, "Fingerspitzengefühl" (intuition), and last but not least trial and error (and crashing it will many times&amp;nbsp;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://ni.lithium.com/i/smilies/16x16_smiley-wink.gif" alt="Smiley Wink" title="Smiley Wink" /&gt; ).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things that are not clear here are how many array pointers will be returned? (The four bytes altered after return would indicate that this is currently 1 but that might change if you change some configuration parameters before the call for instance to aqcuire an entire sequence of images.)&lt;/P&gt;&lt;P&gt;Will the function allocate the pointer array to hold them (unlikely) or not? Will the function allocate the array pointers (likely) or not? If it allocates them which function to use to deallocate them after use? All in all enough to drive a C programmer crazy to implement a call to that function. Now try to do that from within LabVIEW with tricks like MoveBlock etc. etc. and the neatness of LabVIEW where you do not have to worry about memory allocations in general gets rather a curse than an advantage.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would not even consider trying to call that function directly from LabVIEW. Instead I would write a wrapper DLL that does the whole translation between LabVIEW and and this DLL in a way that makes the call in LabVIEW easy to do and the translation performant to be executed. Image acquisition is an area where performance often is beneficial if not mandatory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rolf Kalbermatter &lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by rolfk on &lt;/SPAN&gt;&lt;SPAN class="local-date"&gt; 06-11-2009&lt;/SPAN&gt;&lt;SPAN class="local-time"&gt; 08:37 AM&lt;/SPAN&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 11 Jun 2009 06:37:58 GMT</pubDate>
    <dc:creator>rolfk</dc:creator>
    <dc:date>2009-06-11T06:37:58Z</dc:date>
    <item>
      <title>How to create  a structure pointer DLL using Call Library Function Node</title>
      <link>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/922151#M414717</link>
      <description>&lt;P style="margin: 0in 0in 10pt" class="MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 9pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"&gt;I would like to control the pointer of a user defined structure with call Library function. I wrote a VI for VivaGrabInit, but it always is clashed when I run with a memory error. I desperately need someone's help for right coding. Thank you ahead.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 9pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 9pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 9pt; color: black; line-height: 115%; font-family: 'Arial','sans-serif'"&gt;Function&lt;/SPAN&gt;&lt;/STRONG&gt; &lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;#define VIVAGRAB_FRAME_BUFFER_SIZE&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;0x200000 //2Mb&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;#define VIVAGRAB_FRAME_WIDTH&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;1000&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;#define VIVAGRAB_FRAME_HEIGHT 1000&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;#define VIVAGRAB_FRAME_SIZE&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(VIVAGRAB_FRAME_WIDTH*VIVAGRAB_FRAME_HEIGHT*sizeof(UINT16))&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;#define VIVAGRAB_FRAME_METADATA&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;(VIVAGRAB_FRAME_BUFFER_SIZE-VIVAGRAB_FRAME_SIZE)&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt; &lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;typedef struct&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;{&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Calibri"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;UINT16&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;FrameData[VIVAGRAB_FRAME_HEIGHT][VIVAGRAB_FRAME_WIDTH];&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Calibri"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;UINT8&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Metadata[VIVAGRAB_FRAME_METADATA];&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;} VIVAGRAB_VIDEO_FRAME, *pVIVAGRAB_VIDEO_FRAME, **pVIVAGRAB_VIDEO_FRAME_ARRAY;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt; &lt;P style="margin: 0in 0in 0pt" class="MsoNoSpacing"&gt;&lt;FONT face="Calibri" color="#000000"&gt;extern "C" __declspec(dllexport) UINT32 VivaGrabInit(UINT32 NumFrameBuffers, pVIVAGRAB_VIDEO_FRAME_ARRAY *FrameBuffers);&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2009 16:36:37 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/922151#M414717</guid>
      <dc:creator>AustinPower</dc:creator>
      <dc:date>2009-06-08T16:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  a structure pointer DLL using Call Library Function Node</title>
      <link>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/922286#M414757</link>
      <description>&lt;P&gt;A pointer is just a pointer to a memory location.&amp;nbsp; To do this make a cluster (struct in c) with a 2-d U16 array preallocated to &lt;FONT face="Calibri" color="#000000"&gt;[VIVAGRAB_FRAME_HEIGHT][VIVAGRAB_FRAME_WIDTH] and a 1-d U8 Array preallocated to [VIVAGRAB_FRAME_METADATA];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Pass this to the pointer input of the dll.&amp;nbsp; This should pass the memory location of the pre-allocated (the arrays must have the correct size and type so that memory requirements are correct or you can crash youe application) cluster.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;I think this is how I did this in the past, but I havent used a pointer to a structure in several months.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2009 19:54:01 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/922286#M414757</guid>
      <dc:creator>falkpl</dc:creator>
      <dc:date>2009-06-08T19:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  a structure pointer DLL using Call Library Function Node</title>
      <link>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/922563#M414839</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;falkpl wrote: &lt;BR /&gt;&lt;P&gt;A pointer is just a pointer to a memory location.&amp;nbsp; To do this make a cluster (struct in c) with a 2-d U16 array preallocated to &lt;FONT face="Calibri" color="#000000"&gt;[VIVAGRAB_FRAME_HEIGHT][VIVAGRAB_FRAME_WIDTH] and a 1-d U8 Array preallocated to [VIVAGRAB_FRAME_METADATA];&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Pass this to the pointer input of the dll.&amp;nbsp; This should pass the memory location of the pre-allocated (the arrays must have the correct size and type so that memory requirements are correct or you can crash youe application) cluster.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;I think this is how I did this in the past, but I havent used a pointer to a structure in several months.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt; The OP is a crosspost from &lt;A href="http://forums.lavag.org/DLL-connection-for-pointer-structure-t14248.html" target="_blank"&gt;here&lt;/A&gt;. It is considered polite to mention crossposts in a post! &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to disagree here. First a LabVIEW array in a cluster is not the same as a C array pointer in a structure. One is a LabVIEW handle allocated using the LabVIEW memory manager and really a pointer to a pointer to a data structure that has also the dimension size(s) prepended and the other is just a C pointer. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second, the two arrays in the C code are fixed size and hence get inlined into the structure. This results in a single memory block of the size&amp;nbsp; &lt;FONT face="Calibri" color="#000000"&gt;VIVAGRAB_FRAME_HEIGHT * VIVAGRAB_FRAME_WIDTH * sizeof(&lt;/FONT&gt;&lt;SPAN class="noindex"&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Calibri"&gt;UINT16) + &lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face="Calibri" color="#000000"&gt;VIVAGRAB_FRAME_METADATA * sizof(UINT8).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; So the OP will have to pass a simple LabVIEW byte array as C array pointer instead and then get into the fun of extracting the data correctly from this after the function call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rolf Kalbermatter &lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by rolfk on &lt;/SPAN&gt;&lt;SPAN class="local-date"&gt; 06-09-2009&lt;/SPAN&gt;&lt;SPAN class="local-time"&gt; 10:11 AM&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 09 Jun 2009 08:11:13 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/922563#M414839</guid>
      <dc:creator>rolfk</dc:creator>
      <dc:date>2009-06-09T08:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  a structure pointer DLL using Call Library Function Node</title>
      <link>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/924130#M415334</link>
      <description>&lt;P&gt;Sorry I havent passed a struct to a dll in a while.&amp;nbsp; Now that I look as my old code I have a struct as a preallocated Byte array.&amp;nbsp; I then did simple pointer math to get the offsets of the struct fields (assuming fixed sized fields).&amp;nbsp;There is also the import shared library tool if you have the header files but I have not tried this.&amp;nbsp; I remember it being mentioned at ni week that there was a feature for autowrapping dlls with this wizard.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2009 00:08:11 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/924130#M415334</guid>
      <dc:creator>falkpl</dc:creator>
      <dc:date>2009-06-11T00:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create  a structure pointer DLL using Call Library Function Node</title>
      <link>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/924232#M415366</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;falkpl wrote: &lt;BR /&gt;&lt;P&gt;Sorry I havent passed a struct to a dll in a while.&amp;nbsp; Now that I look as my old code I have a struct as a preallocated Byte array.&amp;nbsp; I then did simple pointer math to get the offsets of the struct fields (assuming fixed sized fields).&amp;nbsp;There is also the import shared library tool if you have the header files but I have not tried this.&amp;nbsp; I remember it being mentioned at ni week that there was a feature for autowrapping dlls with this wizard.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt; The library import wizard is a tool not a magic wand. It can ease import of fairly basic DLL interfaces (the part which is tedious mechanical work) but it can not solve complicated C datatypes and pointer constructs eventhough it does attempt to do some of that too. But C is such a loosely defined language in that respect that one can not possibly think of all possibilities in which pointers and C datatypes can be mixed up by programmers to the point that no automated tool is able to translate it into a fixed typed language like LabVIEW.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add to that that LabVIEW has not really an internal concept of pointers and especially function pointers and the whole exercise to translate some complicated APIs is in vain. While function pointers are simply to difficult to really implement in LabVIEW directly you can trick with complicated data pointer constructs by using rather complicated techniques in the LabVIEW diagram.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the function wants to get passed or probably more likely will return in a pointer a pointer array of array pointers! Anyone still with me after this sentence? Whoever has trouble to understand the implications of this sentence I would suggest to move on and try another exercise. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://ni.lithium.com/i/smilies/16x16_smiley-happy.gif" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For those still following, the C prototype in the header file does not specify many aspects of this at all. This must be determined from the manual, the context of the API, other C sample code using that function, "Fingerspitzengefühl" (intuition), and last but not least trial and error (and crashing it will many times&amp;nbsp;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://ni.lithium.com/i/smilies/16x16_smiley-wink.gif" alt="Smiley Wink" title="Smiley Wink" /&gt; ).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things that are not clear here are how many array pointers will be returned? (The four bytes altered after return would indicate that this is currently 1 but that might change if you change some configuration parameters before the call for instance to aqcuire an entire sequence of images.)&lt;/P&gt;&lt;P&gt;Will the function allocate the pointer array to hold them (unlikely) or not? Will the function allocate the array pointers (likely) or not? If it allocates them which function to use to deallocate them after use? All in all enough to drive a C programmer crazy to implement a call to that function. Now try to do that from within LabVIEW with tricks like MoveBlock etc. etc. and the neatness of LabVIEW where you do not have to worry about memory allocations in general gets rather a curse than an advantage.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would not even consider trying to call that function directly from LabVIEW. Instead I would write a wrapper DLL that does the whole translation between LabVIEW and and this DLL in a way that makes the call in LabVIEW easy to do and the translation performant to be executed. Image acquisition is an area where performance often is beneficial if not mandatory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rolf Kalbermatter &lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by rolfk on &lt;/SPAN&gt;&lt;SPAN class="local-date"&gt; 06-11-2009&lt;/SPAN&gt;&lt;SPAN class="local-time"&gt; 08:37 AM&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 11 Jun 2009 06:37:58 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabVIEW/How-to-create-a-structure-pointer-DLL-using-Call-Library/m-p/924232#M415366</guid>
      <dc:creator>rolfk</dc:creator>
      <dc:date>2009-06-11T06:37:58Z</dc:date>
    </item>
  </channel>
</rss>

