<div dir="ltr"><div dir="ltr">Hi there,<br><br>I'm trying to use a method from an external library whose signature is as follow<br><br>int __stdcall assemble_vdm( ais_state *state, char *str )<br><br>ais_state is:<br><br>#define SIXBIT_LEN  255<br><br>typedef struct {<br>   unsigned char msgid;              //!< Message ID 0-31<br>   unsigned int sequence;           //!< VDM message sequence number<br>   unsigned int total;              //!< Total # of parts for the message<br>   unsigned int num;                //!< Number of the last part stored<br>   char         channel;            //!< AIS Channel character<br>   sixbit       six_state;          //!< sixbit parser state<br>} ais_state;<br><br>six_state is:<br><br>typedef struct {<br>   char bits[SIXBIT_LEN];         //!< raw 6-bit ASCII data string<br>   char *p;                       //!< pointer to current character in bits<br>   unsigned char remainder;       //!< Remainder bits<br>   unsigned char remainder_bits;  //!< Number of remainder bits<br>} sixbit;<br><br>I declared them all as follow:<br><br>Public Struct sixbit<br> bits[255] As Byte                              'raw 6 - bit ASCII data string --> era [SIXBIT_LEN - 1]<br> p As String                                   'pointer To current character In bits<br> remainder As Byte                              'Remainder bits<br> remainder_bits As Byte                         'Number Of remainder bits<br>End Struct<br><br>Public Struct AIS_State<br>   msgid As Byte                              'Message ID 0 - 31<br>   sequence As Short                        'era DWORD; / / ! < VDM message sequence number<br>   total As Short                           'era DWORD; / / ! < Total # Of parts For the message<br>   num As Short                             'era DWORD; / / ! < Number Of the Last part stored<br>   channel As Byte                            ': Char; / / ! < AIS Channel character<br>   six_state As SixBit                        '; / / ! < sixbit parser state<br>End Struct<br><br>Private Extern assemble_vdm(state As AIS_State, str1 As String) As Integer<br><br>Ok....<br>In my Main method I call the assemble_vdm function and the result is as expected, returning an integer between 0 and 5 meaning what's going on, I can confirm it by changing the second parameter's contents. But that method, modifies the first parameter (state) internally, and I should use it afterwards to decide what do to, reading state.msgid<br><br>The fact is, when I read it, its empty and rises segfault.... Does anyone knows how to deal with it?<br><br>The library's sources are at <a href="https://github.com/bcl/aisparser/tree/master/c">https://github.com/bcl/aisparser/tree/master/c</a><br><br>Attached are my sources.<br><br>Greetings,<br></div></div>