martin67 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I've started to use XS for interfacing an existing C library. It works so far until I come to passing integer pointers. I could really use some help here...
The C function is defined as
My definition in the XS file look like this:int WINAPI tdSensor( char * protocol, int protocolLen, char * model, int modelLen, int * id, int * dataTypes ) Use this function to iterate over all sensors. Iterate until TELLSTICK +_SUCCESS is not returned. Parameters: [out] protocol A by ref string where the protocol of the sensor +will be placed. [in] protocolLen The length of the protocol parameter. [out] model A by ref string where the model of the sensor will b +e placed. [in] modelLen The length of the model parameter. [out] id A by ref int where the id of the sensor will be placed. [out] dataTypes A by ref int with flags for the supported sensor + values. Returns: TELLSTICK_SUCCESS if there is more sensors to be fetched.
I had to add a definition in my typedef file:int tdSensor(protocol, protocolLen, model, modelLen, id, dataTypes) char * protocol int protocolLen char * model int modelLen int * id int * dataTypes
But this doesn't work as I think it should. I've tried with T_PV and T_PTRREF but no luck. When I call the code from my test program it looks like this:TYPEMAP int * T_PTR
I'm not really sure how I should call the function from Perl. Trial and error gave me that I needed to set a value on the strings (protocl & model) before calling tdSensor. But this does not seem to work for the integer pointers. Or should I call them like '\$sensorID' instead?my $protocol = "aaaaaaaaaaaaaaaaaaaaaaaaa"; my $model = "bbbbbbbbbbbbbbbbbbbbbbbbb"; my $sensorId = 1; my $dataTypes = 2; while (TellStick::tdSensor($protocol, 25, $model, 25, $sensorId, $data +Types) == TELLSTICK_SUCCESS) { print "res: $res, protocol: $protocol, model: $model, sensorId: $sen +sorId, dataTypes: $dataTypes\n"; }
It seems like it should be pretty trivial to pass a integer pointer so I hope to get some wisdom on how to do this from the Monks...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Passing integer pointer in XS? (&)
by tye (Sage) on Jul 18, 2016 at 18:35 UTC | |
by martin67 (Novice) on Jul 18, 2016 at 20:32 UTC | |
by tye (Sage) on Jul 18, 2016 at 20:42 UTC | |
by ikegami (Patriarch) on Jul 18, 2016 at 21:38 UTC | |
by tye (Sage) on Jul 18, 2016 at 21:51 UTC | |
| |
by martin67 (Novice) on Jul 18, 2016 at 21:04 UTC | |
Re: Passing integer pointer in XS?
by ikegami (Patriarch) on Jul 18, 2016 at 20:23 UTC | |
by martin67 (Novice) on Jul 18, 2016 at 20:56 UTC | |
by tye (Sage) on Jul 18, 2016 at 21:10 UTC | |
by ikegami (Patriarch) on Jul 18, 2016 at 21:31 UTC | |
by tye (Sage) on Jul 18, 2016 at 22:14 UTC | |
| |
by ikegami (Patriarch) on Jul 18, 2016 at 21:18 UTC | |
Re: Passing integer pointer in XS?
by ikegami (Patriarch) on Jul 18, 2016 at 19:55 UTC |
Back to
Seekers of Perl Wisdom