Re: Call-backs

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Tue, 15 Feb 2005 21:33:17 +1100, Patrick Barnes <mrtrick at gmail.com> wrote:
> I'm calling functions in a dll... one of them takes a pointer to this
> struct as a parameter.
> 
> <c code>
> typedef struct dsFunctions {
>   int version;                  /* put DS_VERSION here */
>   /* version 1 data */
>   void (*start)();              /* called before sim loop starts */
>   void (*step) (int pause);     /* called before every frame */
>   void (*command) (int cmd);    /* called if a command key is pressed */
>   void (*stop)();               /* called after sim loop exits */
>   /* version 2 data */
>   char *path_to_textures;       /* if nonzero, path to texture files */
> } dsFunctions;
> </c code>
> 
> The C test program does this:
> <c code>
>   // setup pointers to callback functions
>   dsFunctions fn;
>   fn.version = DS_VERSION;
>   fn.start = &start;
>   fn.step = &simLoop;
>   fn.command = command;
>   fn.stop = 0;
>   fn.path_to_textures = 0;      // uses default
> </c code>
> 
> start is "void start()",
> simLoop is "void simLoop(int pause)",
> command is "void command(int cmd)"
> 
> (minor) why is fn.command assigned command directly, not &command?
> 
> What size are each of those elements in the function, and what do I
> have to poke into the call_back spaces? The return value from
> call_back()?

Hmm, this doesn't work properly... the return-type of the functions in
the struct is void (isn't it?), but Euphoria won't let me use
call_back() on a procedure.

What to do?
-- 
MrTrick

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu