Passaggio puntatore di classe in CreateThread

L

lamilla

Salve a tutti,
sto creando una applicazione che istanzia un thread al quale viene
passato come argomento il puntatore ad una classe che contiene molte
funzioni alcune delle quali devono essere necessariamente static. Non
trovando nessun esempio in giro e non sapendo come referenziare le
variabili globali di classe CIndiceSP nelle funzioni static della
classe stessa ho utilizzato questo metodo che non mi crea nessun
errore di compilazione ma non mi sembra molto pratico.
Volevo sapere se per voi è corretto il modo in cui ho impostato il
codice o se usualmente si programma diversamente.

Allego il codice sperando possa essere chiaro.
Grazie in anticipo

#include "IndiceSP.h"

CAlbero albero;
CIndiceSP* p_indsp;

int main ( void )
{
p_indsp = new CIndiceSP(INFOContext, albero);

HANDLE IhThread = CreateThread(
NULL,
0,

(LPTHREAD_START_ROUTINE)(SubscribeIndiceSP),
&p_indsp,
0,
&ThreadIdInd);

do
{
GetExitCodeThread(IhThread, &exitCode);
Sleep(1000);
} while (exitCode==STILL_ACTIVE);

{....}

}

//--- funzione del main -------------//
DWORD SubscribeIndiceSP(LPVOID arg)
{
CIndiceSP* p_indsp = (CIndiceSP*)arg;

int errcode = p_indsp->Subscribe();

if (errcode != 1 )
{
printf( "Sottoscrizione INDICE_SP fallita\n" );
ExitThread(EXIT_FAILURE);
}
else
{
printf( "Sottoscrizione INDICE_SP attiva!!!!\n" );
}

return 0;
}

////////CLASSE CIndiceSP /////////////////////////////////////
#include "IndiceSP.h"

extern CIndiceSP* p_indsp; ////è corretto?

CIndiceSP::CIndiceSP(AMI_Context_t Contesto, CAlbero& a)
{
INFOContext = Contesto;
albero = &a;

gAppISP = APPINFO_ERROR;
status_ind = AMI_FAILURE;

}

DWORD CIndiceSP::Subscribe() //funzione static
{

if ( p_indsp->gAppISP != AMI_SUCCESS ) ///gAppISP: variabile di
classe gAppISP
{
printf( "\nCIndiceSP.Subscribe() failed\n" );
return EXIT_FAILURE;
}

else
{
return EXIT_SUCCESS;
}

printf ( "Stop CIndiceSP.Subscribe\n" );
}
 
M

msalters

lamilla said:
Salve a tutti,

Sorry, this group accepts English posts only, and only on standard
C++. CreateThread is a Windows function, so please go to an italian
Windows group.

PS.
Use English comments, please, even in code you do not expect to
leave your company. Code in English is more valuable because there
are more people who can read English.

Regards,
Michiel Salters
 
V

Victor Bazarov

lamilla said:
Salve a tutti,
sto creando [..]

You probably need to post to it.comp.lang.c++ ... This NG speaks English.
And since I don't know the rules of the it.comp.* NGs, I cannot say
anything about the topicality of your CreateThread question there. I can
say, however, that here it's OT (even if asked in English) because the C++
_language_ doesn't have threads in it (yet). You might want to look into
reading 'microsoft.public.vc.language' or some other Microsoft forum like
'comp.os.ms-windows.programmer.win32'.

V
 
V

Victor Bazarov

msalters said:
Sorry, this group accepts English posts only, and only on standard
C++. CreateThread is a Windows function, so please go to an italian
Windows group.

PS.
Use English comments, please, even in code you do not expect to
leave your company. Code in English is more valuable because there
are more people who can read English.

I wonder about the latest statistics on the subject. There quite a few
people on the planet who can read Spanish and Chinese. I hope you're not
suggesting that if there are more Spanish-reading folks out there, we all
should switch to writing our comments in Spanish...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top