If you are using letter mode ("P"), put , 0, and it will be null. Do not write , "0",, that is a string. This is undocumented in the stable Win32::API on CPAN right now (the alpha version of Win32::API fixes the POD and finally says how to pass NULL for letter P parameter, it isn't undef due to backcompat, for C prototype mode, undef is NULL, which is normal IMO, I am not a fan of tye's , [], meaning NULL convention, but TIMTOWTDI), but it has been that way since forever I think http://github.com/bulk88/perl5-win32-api/blob/6466f18dc13e33cf4a07e54e5c76164444b33b1b/API.xs#L320 Next, F letter is a 32 bit floating pointer number, D is a 64 bit floating pointer number. I assume your float64 is a double in C. So that is wrong. Change the F to a D. You didn't say what bit CPU you are on (32/64), but if you are on 32 bits, and you replace a 8 byte param with 4 byte or vice versa, ALL parameters to the right of the replaced one become garbage. With your F, dataLayout in perl in the eyes of the function become part of the timeout, writeArray in Perl became dataLayout, sampsPerChanWritten in Perl became writeArray, reserved/your NULL became sampsPerChanWritten, and the C func, for reserved didn't see NULL but non-NULL garbage (probably the C instruction return address). On 64 bits all C stack params are extended to 8 bytes each and stay at 8, so what I described happens on 32 bits, wouldn't happen on 64. On 64, corrupt params keep their corruption to themselves and dont spill it over into neighboring params.

Next, in your pack stuff, why did you use N instead of V or L (L is the most appropriate pack letter to use).

my $sampsPerChanWritten= pack("N4",0,0,0,0);
Why? int32 *sampsPerChanWritten should be my $sampsPerChanWritten= pack('L', 0)"; not an array of Ls. It is just one according to the prototype (then again I dont have access to the formal docs for that function, that might a pointer to just one int32, or many int32s and the length of the array is some other param to the func). If I read the docs for that function http://zone.ni.com/reference/en-XX/help/370471W-01/daqmxcfunc/daqmxwritedigitalu32/, $writearray should just be pack('L', 0), just one L, since $numSamps is 1. BTW, as a performance increase, you could write $writearray = "\x00\x00\x00\x00"; or $writearray = "\x00" x 4; instead of $writearray = pack('L', 0);. They are equal. Test it with eq operator if you dont believe me.

In reply to Re: Win32::API pointers / NULL by bulk88
in thread Win32::API pointers / NULL by ghardy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.