Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Passing integer pointer in XS?

by ikegami (Patriarch)
on Jul 18, 2016 at 19:55 UTC ( [id://1167988]=note: print w/replies, xml ) Need Help??


in reply to Passing integer pointer in XS?

[ 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1167988]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found