Sorry.Several Threads 
Author Message
 Sorry.Several Threads

MY HISTORY:

Quote:
>>I have a problem. I want to create several threads in a program. I
have
>>a Process that define a statechart. I want to create several
statechart,
>>runing together. I use the sentence "_beginthead" and I have a error.
I
>>ask for the problem:
>>" : error C2664: '_beginthread' : cannot convert parameter 1 from
>>'void
>> (int *)' to 'void (__cdecl *)(void *)'
>> The sentence is:         _beginthread(Process,0,( int *)(ch));   in

'ProyectoDlg.cpp'

Quote:
>> and Process is defined:        void Process(int *ch);"        in

'ProyectoDlg.h'
and Process description is void CProyectoDlg::Process(int *ch){

Quote:
}        in ''ProyectoDlg.cpp'

AND THE REPLY WAS:

Quote:
>you gave me a 'void (int*)' parameter but I want a 'void
(__cdecl*)(void*)'
>parameter.
>It means that you declared your function as you stated:
>void MyThreadFunction(int *ch);

>but it *has* to be:
>void __cdecl MyThreadFunction(void* ch);    // __cdecl added and int*
became
>void*

>Can you feel the difference ?
>If in your code you want to use an int* ch then do the following:

>void __cdecl MyThreadFunction(void* ch2)
>{
>    int* ch = (int*)ch2;
>    // do what you want now with ch
>}

BUT I HAVE NOW:

error C2664: '_beginthread' : cannot convert parameter 1 from 'void
(void *)' to 'void (__cdecl *)(void *)'

 The sentence is:         _beginthread(Process,0,( void *)(ch));   in
'ProyectoDlg.cpp'

 and Process is defined:        void _cdecl Process(void *ch);"
in 'ProyectoDlg.h'

and Process description is void _cdecl CProyectoDlg::Process(void *ch){

Quote:
}        in ''ProyectoDlg.cpp'

Sorry, because my english isn't very good.

         Thanks,  Javi



Fri, 28 Jun 2002 03:00:00 GMT  
 Sorry.Several Threads
Javi,

I see 2 problems in it:
1. __cdel has 2 '_', you put only 1.
2. it seems that your function is inside a class. May I suggest to place
your class outside the class definition and pass the this pointer when
starting the thread:

here is an example
in your .h file:

class MyClass
{
    int m_integer;
    int Function1(...);
    BOOL Function2(...);
    // .......

Quote:
};

in your .cpp file:

void __cdelc MyThreadFunction (void *argument)
{
    MyClass *pMyClass = (MyClass*)argument;
    // now you can use pMyClass->m_integer, pMyClass->Function2()...

Quote:
}

MyClass::Function1(...)
{
    // Create the thread and give a pointer to ourself
    // of course we should not die or the thread will fail
    _beginthread(MyThreadFunction, 0, (void*)this);
    // continue...

Quote:
}

Hope this is clearer now
Guillaume.
Quote:

>MY HISTORY:

>>>I have a problem. I want to create several threads in a program. I
>have
>>>a Process that define a statechart. I want to create several
>statechart,
>>>runing together. I use the sentence "_beginthead" and I have a error.
>I
>>>ask for the problem:

>>>" : error C2664: '_beginthread' : cannot convert parameter 1 from
>>>'void
>>> (int *)' to 'void (__cdecl *)(void *)'

>>> The sentence is:         _beginthread(Process,0,( int *)(ch));   in
>'ProyectoDlg.cpp'

>>> and Process is defined:        void Process(int *ch);"        in
>'ProyectoDlg.h'
>and Process description is void CProyectoDlg::Process(int *ch){

>}        in ''ProyectoDlg.cpp'

>AND THE REPLY WAS:

>>you gave me a 'void (int*)' parameter but I want a 'void
>(__cdecl*)(void*)'
>>parameter.

>>It means that you declared your function as you stated:
>>void MyThreadFunction(int *ch);

>>but it *has* to be:
>>void __cdecl MyThreadFunction(void* ch);    // __cdecl added and int*
>became
>>void*

>>Can you feel the difference ?
>>If in your code you want to use an int* ch then do the following:

>>void __cdecl MyThreadFunction(void* ch2)
>>{
>>    int* ch = (int*)ch2;
>>    // do what you want now with ch
>>}

>BUT I HAVE NOW:

>error C2664: '_beginthread' : cannot convert parameter 1 from 'void
>(void *)' to 'void (__cdecl *)(void *)'

> The sentence is:         _beginthread(Process,0,( void *)(ch));   in
>'ProyectoDlg.cpp'

> and Process is defined:        void _cdecl Process(void *ch);"
>in 'ProyectoDlg.h'

>and Process description is void _cdecl CProyectoDlg::Process(void *ch){

>}        in ''ProyectoDlg.cpp'

>Sorry, because my english isn't very good.

>         Thanks,  Javi



Sat, 29 Jun 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Several threads, help

2. Several Threads. Help me

3. Several Threads in one Process

4. executing function from several threads

5. a dll, several threads and one dialog...

6. a dll, several threads and one dialog...

7. several doc/views + threads

8. Sorry, lost thread, Re: Strip Charts.

9. Several bugs, spanning several products (VS.Net, OfficeXP)

10. Sorry Sorry

11. SORRY , SORRY, FOR THE NUMEROUS MESSAGES IN YOUR NEWS GROUP

12. threads, threads, and more threads

 

 
Powered by phpBB® Forum Software