By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Passaggio puntatore di classe in CreateThread

P: n/a
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" );
}
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
lamilla wrote:
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

Jul 23 '05 #2

P: n/a
lamilla wrote:
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
Jul 23 '05 #3

P: n/a
msalters wrote:
lamilla wrote:
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.


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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.