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