<?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: Passing a void* (from an allocated buffer) inside a struct to a C dll in NI TestStand</title>
    <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279904#M8564</link>
    <description>One idea is that you could create a separate data type for each of the
possibilities and use the one that's most appropriate for a particular
call (especially if the data type is based on input information which
you already have before making the call). The field could be identical
in all of the datatypes (i.e. an array of numbers), just the c struct
info for the data type would need to be different (make sure you set
its "Store As" type to Pointer to Array if you want it to map to a void
* in your struct). This really only matters for your C calls as labview
will always get the array of numbers as an array of numbers inside of
its equivalent cluster.&lt;BR /&gt;
&lt;BR /&gt;
Something important to keep in mind though is that if you have
teststand passing in these arrays, you shouldn't be trying to
reallocate them inside of your C code modules. The code modules can
access the memory that teststand's allocated (the array size is the
memory size), but the code module can not reallocate or free the memory.&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps,&lt;BR /&gt;
-Doug&lt;BR /&gt;
&lt;BR /&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 20 Oct 2005 17:34:13 GMT</pubDate>
    <dc:creator>dug9000</dc:creator>
    <dc:date>2005-10-20T17:34:13Z</dc:date>
    <item>
      <title>Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/278977#M8541</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Hello,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Currently testing the potential of TestStand and I am stuck on one small problem. &lt;/DIV&gt;
&lt;DIV&gt;I have seen similar question, but no real answer (or I could not understand them)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;The C function prototype looks like this:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&lt;FONT size="2"&gt;TSDLL_API int32 TSTransfer(int32 hSystem, PIN_PARAMS_TRANSFERDATA pInData, POUT_PARAMS_TRANSFERDATA pOutData)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;where the structure PIN_PARAMS_TRANSFERDATA&amp;nbsp;is defined as&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff"&gt;typedef&lt;/FONT&gt;&lt;FONT color="#000000"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff"&gt;struct&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;FONT size="2"&gt;uInt16 u16Channel; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#008000"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;uInt32 u32Mode; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#008000"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;uInt32 u32Segment; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#008000"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;int64 i64StartAddress;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;int64 i64Length;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff"&gt;void&lt;/FONT&gt; * pDataBuffer; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;FONT color="#008000"&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;HANDLE *hNotifyEvent; &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;} IN_PARAMS_TRANSFERDATA, *PIN_PARAMS_TRANSFERDATA;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;So, &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;How should the structure be represented in the Type gallery of TestStand??&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;How can I allocate a buffer (Array of Int8, or Int16 or Int32) and assigned it to the struct? &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I would like to use&amp;nbsp;a local variable that could be filled with the requested data so it could be used with further test.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Thanks&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Eric&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 18 Oct 2005 18:42:30 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/278977#M8541</guid>
      <dc:creator>Gig52</dc:creator>
      <dc:date>2005-10-18T18:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279532#M8546</link>
      <description>If you want to pass a struct from TestStand to the C DLL you can consider creating a custom data type in the type palette and passing it through.  A pointer can be cast to any data type you wish.  TestStand does support the void data type to pass data. &lt;BR /&gt;You may also want to consider passing the void data in as an int pointer and then casting it back to a void.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;Nandini&lt;BR /&gt;NI</description>
      <pubDate>Wed, 19 Oct 2005 22:14:03 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279532#M8546</guid>
      <dc:creator>nandini</dc:creator>
      <dc:date>2005-10-19T22:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279813#M8558</link>
      <description>Do you want to allocate the data buffer inside of teststand or in your
dll? You have to be careful because the memory has to be deallocated by
the same environment that allocated it or you could end up corrupting
or leaking memory. Another issue is do you need the data to be written
to and read from the buffer directly inside of teststand our only from
your dll or some sort of combination of the two?&lt;BR /&gt;
&lt;BR /&gt;
Basically if you just need teststand to hold the pointer you can just
tell teststand that that field in the structure is a 32-bit integer
(same size as a pointer in C) then things should work ok as long as you
only access it from inside your dll (i.e. teststand can hold the value
of the pointer this way, but will only see it as an integer on the
teststand side).&lt;BR /&gt;
&lt;BR /&gt;
If instead you want to be able to allocate the buffer directly in
teststand and read/write to it in both teststand and your dll, then
things can get more complicated, please provide more details if this is
the case to explain exactly what you want to be able to do with this
data type both inside of teststand and in your dll.&lt;BR /&gt;
&lt;BR /&gt;
Also, do you already know how to define c structs in teststand or are
you asking about that too or just what you should do for this
particular field?&lt;BR /&gt;
&lt;BR /&gt;
-Doug&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Oct 2005 14:48:13 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279813#M8558</guid>
      <dc:creator>dug9000</dc:creator>
      <dc:date>2005-10-20T14:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279870#M8561</link>
      <description>I already know how to define C struct in TestStand. So far, the one i needed were straightforward.&lt;BR /&gt;
&lt;BR /&gt;
My question is really oriented toward the void* inside the struct.&lt;BR /&gt;
&lt;BR /&gt;
In&amp;nbsp; this case, I want to create the "buffer" in TestStand, then
pass it to the C dll as a void* to be filled in since the value might
be Int8, Int16 or Int32 based on the input. The usage for this is to
have TestStand act a the middleman (as it is supposed to) and get the
data from 1 input and then use the given input in other tests, either
in C or Labview.&lt;BR /&gt;
&lt;BR /&gt;
So, I guess from the comment I read it is possible, but how? And&amp;nbsp;
is it worth the trouble or are there better alternatives (easier,
safer)? &lt;BR /&gt;
I guess the same approach would be easier if instead of having a C dll
to fill in the buffer, I would have a&amp;nbsp; LabView&amp;nbsp; vi&amp;nbsp; to
perform the same action? &lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Oct 2005 16:31:18 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279870#M8561</guid>
      <dc:creator>Gig52</dc:creator>
      <dc:date>2005-10-20T16:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279904#M8564</link>
      <description>One idea is that you could create a separate data type for each of the
possibilities and use the one that's most appropriate for a particular
call (especially if the data type is based on input information which
you already have before making the call). The field could be identical
in all of the datatypes (i.e. an array of numbers), just the c struct
info for the data type would need to be different (make sure you set
its "Store As" type to Pointer to Array if you want it to map to a void
* in your struct). This really only matters for your C calls as labview
will always get the array of numbers as an array of numbers inside of
its equivalent cluster.&lt;BR /&gt;
&lt;BR /&gt;
Something important to keep in mind though is that if you have
teststand passing in these arrays, you shouldn't be trying to
reallocate them inside of your C code modules. The code modules can
access the memory that teststand's allocated (the array size is the
memory size), but the code module can not reallocate or free the memory.&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps,&lt;BR /&gt;
-Doug&lt;BR /&gt;
&lt;BR /&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Oct 2005 17:34:13 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279904#M8564</guid>
      <dc:creator>dug9000</dc:creator>
      <dc:date>2005-10-20T17:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279911#M8565</link>
      <description>Just want to add that storing a pointer as a 32-bit integer like I
previously suggested could lead to trouble in the future when all the
software involved has switched over to the 64-bit architecture as
pointers will then be 64-bits long. So it might be best to avoid doing
that. In this particular case there's probably a better solution anyway
(see later posts).&lt;BR /&gt;
&lt;BR /&gt;
-Doug&lt;BR /&gt;
&lt;BR /&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Oct 2005 17:49:25 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/279911#M8565</guid>
      <dc:creator>dug9000</dc:creator>
      <dc:date>2005-10-20T17:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/280417#M8577</link>
      <description>One thing important to note when casting a void pointer to an int is that the method is ok only on 32-bit systems.  This would however, create a problem on a 64-bit system.  The reason is that on 64-bit systems, a coid pointer is a 64 bit value and all ints aer 32 bits.  Casting 64 bit data into 32 bits can cause the problem to occur.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;Nandini&lt;BR /&gt;NI</description>
      <pubDate>Fri, 21 Oct 2005 19:17:55 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/280417#M8577</guid>
      <dc:creator>nandini</dc:creator>
      <dc:date>2005-10-21T19:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a void* (from an allocated buffer) inside a struct to a C dll</title>
      <link>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/280924#M8592</link>
      <description>Nandini,&lt;BR /&gt;

&lt;BR /&gt;

Just want to add that it's only a problem on 64-bit systems if you are
running 64-bit software (64-bit Windows can still run 32-bit apps and
TestStand is currently a 32-bit app). Anyway, this is all getting off
topic. Sorry about that.&lt;BR /&gt;

&lt;BR /&gt;

Gig52, if you still need help with the original problem, please let us know.&lt;BR /&gt;

&lt;BR /&gt;

-Doug&lt;BR /&gt;
&lt;BR /&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 24 Oct 2005 14:39:10 GMT</pubDate>
      <guid>https://forums.ni.com/t5/NI-TestStand/Passing-a-void-from-an-allocated-buffer-inside-a-struct-to-a-C/m-p/280924#M8592</guid>
      <dc:creator>dug9000</dc:creator>
      <dc:date>2005-10-24T14:39:10Z</dc:date>
    </item>
  </channel>
</rss>

