Calling C library functions from basic with string parameter (228 Views)
Reply
Advisor
AlexanderM
Posts: 19
Registered: ‎09-26-2013
Message 1 of 6 (228 Views)
Accepted Solution

Calling C library functions from basic with string parameter

Hello to everyone.

The question is: 

Is there an simple way to form '\0' terminated c-string in basic to pass it as an argument in C library's function?

Library's function notification:

int login(char * login, char * password);

 

 

Please use plain text.
Advisor
AlexanderM
Posts: 19
Registered: ‎09-26-2013
Message 2 of 6 (224 Views)

Re: Calling C library functions from basic with string parameter

So, the simplest way for me is to create wrapping functions over my library function and transfer a pointer to string for a parsing in C.

But it is not neat-looking solution.  Furthermore I've not managed to find how to get a pointer in basic yet.

Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,036
Registered: ‎02-23-2005
Message 3 of 6 (213 Views)

Re: Calling C library functions from basic with string parameter

Please use plain text.
Advisor
AlexanderM
Posts: 19
Registered: ‎09-26-2013
Message 4 of 6 (207 Views)

Re: Calling C library functions from basic with string parameter

Thanks. It is the exactly what I am looking for). There are only one task: to convince the library's users do not forget add 0 in the end of string.
Please use plain text.
Honored Contributor
Steven Schweda
Posts: 9,036
Registered: ‎02-23-2005
Message 5 of 6 (184 Views)

Re: Calling C library functions from basic with string parameter

Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,578
Registered: ‎05-19-2003
Message 6 of 6 (130 Views)

Re: Calling C library functions from basic with string parameter

 

For sake of completeness...

 

>>  Furthermore I've not managed to find how to get a pointer in basic yet.

 

Basic has the LOC function to return the address of a variable.

 

Note:  "For dynamic strings, the LOC function returns the address of the descriptor rather than the address of the data."

 

For a dynamic string you can use LIB$ANALYZE_SDESC  to get the actual address, but that gets tedious.

 

One option is to use a static / fixed string in a MAP, copy in the string , use (left side)  MID$ to put a NULL at the desired offset, pass the address of the (fixed) string using LOC.

 

This may sound like a lot of overhead, but please realize the operations like 'cstr+ "0"c' will also copy the strings around and allocate descriptors and stuff.

 

Hein.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation