Hi Andrew,<div><br></div><div>It's a really central and recurring question you raised. If you'd want to share your wisdom on this on the Wiki in a way that would have been of help to you in the first place would be great.</div>

<div><br></div><div>Ah btw, regarding C stack frames, remember you need to rewind them in the right order and that they never GC. Gambit does not throw an exception when rewinding in the wrong order (for performance reasons I suppose), but generally the app fails or something, don't remember.</div>

<div><br></div><div>Brgds,</div><div>Mikael</div><div><br></div><div><div class="gmail_quote">2012/7/3 Andrew Suttles <span dir="ltr"><<a href="mailto:andrew.suttles@gmail.com" target="_blank">andrew.suttles@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Folks -<br><br><br>I am writing a simple Windows native app in C using Win32 libraries.  I'd like to to have some of my Windows callback functions call routines that I've written (or will write) in GambitC (because scheme is more fun to write and maintain than C).  I've found material on how to call functions written in C in the scheme interpreter process, but not the other way around.  In other words, when I compile a module of scheme functions into an object file, I don't have a header file to include in my main program written in C.  How do I call those scheme functions?<br>

<br>Thanks again for the help.  I'm fairly new to Scheme and I'm *very new* to GambitC, so please excuse the the naivete of my question.<span class="HOEnZb"><font color="#888888"><br><br>Andrew<br></font></span></blockquote>

<br class="Apple-interchange-newline"></div><br><div class="gmail_quote">2012/7/3 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im"><br>
On 2012-07-03, at 10:09 AM, Andrew Suttles wrote:<br>
<br>
> Folks -<br>
><br>
><br>
> I am writing a simple Windows native app in C using Win32 libraries.  I'd like to to have some of my Windows callback functions call routines that I've written (or will write) in GambitC (because scheme is more fun to write and maintain than C).  I've found material on how to call functions written in C in the scheme interpreter process, but not the other way around.  In other words, when I compile a module of scheme functions into an object file, I don't have a header file to include in my main program written in C.  How do I call those scheme functions?<br>


<br>
</div>To expose a C function to Scheme you use c-lambda as in<br>
<br>
(define puts (c-lambda (char-string) int "puts"))<br>
<br>
The string "puts" is the name of the function in C, and the Scheme puts global variable is what is used to call the function from Scheme code, i.e. (puts "hello!").<br>
<br>
To expose a Scheme function to C you use c-define as in<br>
<br>
(c-define (write-log s) (char-string) void "write_log" ""<br>
  (display "log: ")<br>
  (display s))<br>
<br>
The string "write_log" is the name of the C function to call to execute the write-log Scheme function.  In general you will also want to have a header file, say log.h which contains the prototype of this function:<br>


<br>
/* File: log.h */<br>
void write_log(char *s);<br>
<br>
So a module of C code using the write_log function will look like:<br>
<br>
#include "log.h"<br>
<br>
int main()<br>
{<br>
  write_log("hello\n");<br>
  return 0;<br>
}<br>
<br>
Don't forget that you need to initialize the Scheme program and runtime system by firs calling ___setup (see the example in examples/pthread).<br>
<br>
Marc<br>
<br>
Marc<br>
<br>
_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
</blockquote></div><br></div>