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
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.
My definition in the XS file look like this:
int tdSensor(protocol, protocolLen, model, modelLen, id, dataTypes) char * protocol int protocolLen char * model int modelLen int * id int * dataTypes
I had to add a definition in my typedef file:
TYPEMAP int * T_PTR
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:
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"; }
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?

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


In reply to 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":



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