Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

[ Oops! I somehow thought you were using Win32::API and not XS. Ignore this. ]


use feature qw( say state ); use Win32::API qw( ); use constant { _MAX_PROTOCOL_LEN => 25, _MAX_MODEL_LEN => 25, }; use constant { TELLSTICK_SUCCESS => '~~~', }; sub tdSensor { state $tdSensor = Win32::API->new( '~~~.dll', 'tdSensor', 'PIPIPP', 'I', ); my $protocol_buf = "\0" x (_MAX_PROTOCOL_LEN + 1); my $model_buf = "\0" x (_MAX_MODEL_LEN + 1); my $id_buf = pack('i', 0); my $dataTypes_buf = pack('i', 0); my $rv = $tdSensor->Call( $protocol_buf, length($protocol_buf), $model_buf, length($model_buf), $id_buf, $dataTypes_buf, ); if ($rv != TELLSTICK_SUCCESS) { return undef; } return { protocol = unpack('Z*', $protocol_buf), model = unpack('Z*', $model_buf), id = unpack('i', $id_buf), dataTypes = unpack('i', $dataTypes_buf), }; } while (my $rec = tdSensor()) { say join ', ', "protocol: $rec->{protocol}", "model: $rec->{model}", "sensorId: $rec->{id}", "dataTypes: $rec->{dataTypes}"; }

Untested. Assumes a 32-bit build of Perl.


In reply to Re: Passing integer pointer in XS? by ikegami
in thread Passing integer pointer in XS? by martin67

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found