C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

callback dans une classe

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Thierry Schembri
Guest





PostPosted: Wed Jan 14, 2004 1:57 am    Post subject: callback dans une classe Reply with quote



Hello !

Je voudrais définir une fonction callback dans une classe.

ex :

class toto:
{

....

private:

void machin(void);
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE*
pdidInstance, VOID* pContext );


....
};

(Il s'agit du callback d'une fonction d'énumération de joysticks avec Direct
Input).

Bref, quand je fais dans machin ( ):

DI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,NULL,
DIEDFL_ATTACHEDONLY );

J'obtiens fort logiquement un

"error C2664: 'IDirectInput8A::EnumDevices' : cannot convert parameter 2
from 'BOOL (const DIDEVICEINSTANCE *,void *)' to 'LPDIENUMDEVICESCALLBACKA'"

à la compilation.

La solution serait de mettre EnumJoystickCallback en static, mais dans ce
cas, je ne pourrai plus acceder aux membres de ma classe toto à partir de
cette fonction.

Euh... comment faire ?

Merci d'avance.


Back to top
Beru
Guest





PostPosted: Wed Jan 14, 2004 2:25 am    Post subject: Re: callback dans une classe Reply with quote




"Thierry Schembri" <tschembri (AT) hydromail (DOT) net> wrote

Quote:
Hello !

Je voudrais définir une fonction callback dans une classe.

ex :

class toto:
{

....

private:

void machin(void);
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE*
pdidInstance, VOID* pContext );


....
};


Euh... comment faire ?

Déclare une fonction normale (pas dans ta classe) et lorsque tu appelles la
fonction d'énumération, passe lui un pointeur sur ton instance de toto dans
la variable context qui est faite pour ça !

Bonne chance




Back to top
konroth
Guest





PostPosted: Wed Jan 14, 2004 4:30 pm    Post subject: Re: callback dans une classe Reply with quote





Thierry Schembri a écrit:
Quote:
Hello !

Je voudrais définir une fonction callback dans une classe.

ex :

class toto:
{

....

private:

void machin(void);
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE*
pdidInstance, VOID* pContext );


....
};

(Il s'agit du callback d'une fonction d'énumération de joysticks avec Direct
Input).

Bref, quand je fais dans machin ( ):

DI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,NULL,
DIEDFL_ATTACHEDONLY );

J'obtiens fort logiquement un

"error C2664: 'IDirectInput8A::EnumDevices' : cannot convert parameter 2
from 'BOOL (const DIDEVICEINSTANCE *,void *)' to 'LPDIENUMDEVICESCALLBACKA'"

à la compilation.

La solution serait de mettre EnumJoystickCallback en static, mais dans ce
cas, je ne pourrai plus acceder aux membres de ma classe toto à partir de
cette fonction.

Euh... comment faire ?

Merci d'avance.








Back to top
konroth
Guest





PostPosted: Wed Jan 14, 2004 4:32 pm    Post subject: Re: callback dans une classe Reply with quote



Thierry Schembri a écrit:
Quote:
Hello !

Je voudrais définir une fonction callback dans une classe.

ex :

class toto:
{

....

private:

void machin(void);
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE*
pdidInstance, VOID* pContext );


....
};

(Il s'agit du callback d'une fonction d'énumération de joysticks avec Direct
Input).

Bref, quand je fais dans machin ( ):

DI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,NULL,
DIEDFL_ATTACHEDONLY );

J'obtiens fort logiquement un

"error C2664: 'IDirectInput8A::EnumDevices' : cannot convert parameter 2
from 'BOOL (const DIDEVICEINSTANCE *,void *)' to 'LPDIENUMDEVICESCALLBACKA'"

à la compilation.

La solution serait de mettre EnumJoystickCallback en static, mais dans ce
cas, je ne pourrai plus acceder aux membres de ma classe toto à partir de
cette fonction.

Euh... comment faire ?

Merci d'avance.







AVEC static......................

Je vais essayer
Ca devait marcher

class toto:
{

private:
void machin(void);
// static !!!!!!!!!!!!!!!!
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* )
pdidInstance, VOID* pContext );
};


-----------------------------------------









Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.