Operating System - OpenVMS
1748116 Members
3463 Online
108758 Solutions
New Discussion

Calling C library functions from basic with string parameter

 
SOLVED
Go to solution
AlexanderM
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 5
AlexanderM
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.

Steven Schweda
Honored Contributor
Solution

Re: Calling C library functions from basic with string parameter

 
AlexanderM
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.
Steven Schweda
Honored Contributor

Re: Calling C library functions from basic with string parameter

 
Hein van den Heuvel
Honored Contributor

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.