1. Call-backs

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()?

-- 
MrTrick

new topic     » topic index » view message » categorize

2. Re: Call-backs

On Tue, 15 Feb 2005 17:49:03 -0500, Elliott Sales de Andrade wrote:
> 4 bytes, yes.

Thanks.


> PS. I thought we were working on this, eh?

Indeed, this is for the drawstuff library. I haven't seen you on
#euphoria since I managed to build the dll.

-- 
MrTrick

new topic     » goto parent     » topic index » view message » categorize

3. Re: Call-backs

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 message » categorize

4. Re: Call-backs

Patrick Barnes wrote:
> 
> 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?

Just declare it a function, and return zero or something, and the compiled
code will ignore the return value.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu