Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Calling C library functions from basic with string parameter

SOLVED
Go to Solution
Highlighted
Advisor

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);

 

 

5 REPLIES
Advisor

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.

Honored Contributor [Founder]

Re: Calling C library functions from basic with string parameter

 
Advisor

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.
Honored Contributor [Founder]

Re: Calling C library functions from basic with string parameter

 
Honored Contributor [Founder]

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.