[Gambas-user] external functions and structs
gen braga
genbraga1 at gmail.com
Wed Nov 28 13:39:02 CET 2018
Hi there,
I'm trying to use a method from an external library whose signature is as
follow
int __stdcall assemble_vdm( ais_state *state, char *str )
ais_state is:
#define SIXBIT_LEN 255
typedef struct {
unsigned char msgid; //!< Message ID 0-31
unsigned int sequence; //!< VDM message sequence number
unsigned int total; //!< Total # of parts for the message
unsigned int num; //!< Number of the last part stored
char channel; //!< AIS Channel character
sixbit six_state; //!< sixbit parser state
} ais_state;
six_state is:
typedef struct {
char bits[SIXBIT_LEN]; //!< raw 6-bit ASCII data string
char *p; //!< pointer to current character in
bits
unsigned char remainder; //!< Remainder bits
unsigned char remainder_bits; //!< Number of remainder bits
} sixbit;
I declared them all as follow:
Public Struct sixbit
bits[255] As Byte 'raw 6 - bit ASCII data
string --> era [SIXBIT_LEN - 1]
p As String 'pointer To current
character In bits
remainder As Byte 'Remainder bits
remainder_bits As Byte 'Number Of remainder bits
End Struct
Public Struct AIS_State
msgid As Byte 'Message ID 0 - 31
sequence As Short 'era DWORD; / / ! < VDM
message sequence number
total As Short 'era DWORD; / / ! < Total #
Of parts For the message
num As Short 'era DWORD; / / ! < Number Of
the Last part stored
channel As Byte ': Char; / / ! < AIS
Channel character
six_state As SixBit '; / / ! < sixbit parser
state
End Struct
Private Extern assemble_vdm(state As AIS_State, str1 As String) As Integer
Ok....
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
The fact is, when I read it, its empty and rises segfault.... Does anyone
knows how to deal with it?
The library's sources are at https://github.com/bcl/aisparser/tree/master/c
Attached are my sources.
Greetings,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181128/fc077d3c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ais_lib-externo-0.0.2.tar.gz
Type: application/gzip
Size: 35699 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181128/fc077d3c/attachment-0001.gz>
More information about the User
mailing list