[S] using call_S() from MS Visual C++ to S+ (4.0)

Suzanne Cashman (scashman@empnet.com)
Tue, 23 Jun 1998 18:24:53 -0700


Hello, S-users;

I have been unsuccessfully trying to implement the call_S() function from
a dll created in MS Visual C++ calling back to S+ (4.0). Has anyone done
this sucessfully in this environment? Other environments? I have been
trying to get the following simple scenario to work.

>From the output print statement, I know that the program is sucessfully
entering the c code and passing arguments. I am unsure of the argument
casting as online S+ has a different guideline for what should be (void *)
than the document "Interfacing with C & Fortran Code". However, I have
tried each type of casting neither works in my code.

Any assistance would be much appreciated!
-Suzanne

S+ code:

hotel.rpart <- function(y,x){
z_x+20
return(as.integer(z))
}

hotel.test <- function(y, n) {

ret_.C("hotel",
as.character(list(hotel.rpart)),
as.double(y),
as.integer(n))
}

C code:

void hotel(char **function, double *y, int n)
{

float i = 2;

char *modes[]= {"double", "single"};
long lengths[] = {n,1};
char *names[] = {"y", "i"};

void *args[2];
long *result[1];

args[0] = (void *) y;
args[1] = (void *) &i;

printf("function = %s\n", (char *)*function);

call_S((void *) *function, 2L, args, modes, lengths, names, 1L, (char
**)result);

printf("exit hotel\n");
}

When I kick this program off with:

inspect( hotel.test(c(0,1,2,3,4,5,6), 7) )

I get the following results from the inspector:

> inspect(hotel.test(c(0, 1, 2, 3, 4, 5, 6), 7))
entering function hotel.test
stopped in hotel.test (frame 9), at:
return(ret <- .C("hotel",
as.character(list(hotel.rpart)),
as.double(y),
...
d> function = function(y, x)
{
z <- x + 20
return(as.integer(z))
}

Calls at time of error:

11: error = function() from 10
10: .C("hotel", from 9
9: hotel.test(c(0, 1, 2, 3, 4, 5, 6), 7) from 1
8: inspect(hotel.test(c(0, 1, 2, 3, 4, 5, 6), 7)) from 1
7: eval(i, local) from 6
6: source(auto.print = auto.print, exprs = substitute(exprs.literal)) from
5
5: script.run(exprs.literal = { from 1
4: eval(expr, local = F) from 3
3: .Sapi.build.output(txt = from 2
2: .C(NAME = "S_api_get_message", from 1
1: from 1

Dumping frames ... Error in .C("hotel",: Function pointer in call to S: bad
pointer (544868618) for value
Dumped

local frame (frame of error) is .C (frame 10)
d>

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news