Click here to Skip to main content
16,011,988 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRuler Control Pin
FranzAKlein24-Feb-01 2:35
FranzAKlein24-Feb-01 2:35 
GeneralRe: Ruler Control Pin
l a u r e n24-Feb-01 4:02
l a u r e n24-Feb-01 4:02 
GeneralRe: Ruler Control Pin
26-Feb-01 8:24
suss26-Feb-01 8:24 
GeneralRe: Ruler Control Pin
l a u r e n26-Feb-01 10:41
l a u r e n26-Feb-01 10:41 
GeneralRe: Ruler Control Pin
26-Feb-01 22:56
suss26-Feb-01 22:56 
GeneralRe: Ruler Control Pin
Erik Funkenbusch26-Feb-01 12:43
Erik Funkenbusch26-Feb-01 12:43 
GeneralRe: Ruler Control Pin
26-Feb-01 23:26
suss26-Feb-01 23:26 
GeneralCasting thread functions Pin
Joe Moldovan23-Feb-01 23:53
Joe Moldovan23-Feb-01 23:53 
The MSDN tells me that the thread process for CreateThread must be a function of the following form: DWORD WINAPI ThreadProc( LPVOID lpParameter ).

When I implement this as a simple global procedure I have no problems but if I make the function a member of a class (SerialComms for example) C++ refuses to accept it as a parameter and complains about an illegal cast. Nothing I have tried could coax it into recasting to an acceptable value. The pointer it wants is,

DWORD (WINAPI *ThreadFunction )(void *)

but when I point to a member function it actually sees,

DWORD (WINAPI SerialComms::*ThreadFunction )(void *)

As far as I am concerned these are identical except for the namespace. The linkage is identical also so C++ should only warn me and not kill the compile. I have solved this problem as follows:

union
{
DWORD (WINAPI SerialComms::*x )(void *);
DWORD (WINAPI *y )(void *);
} z;

// Get the read thread procedure address. This is a weird "cast" method.
z.x = ThreadFunction;
m_readThread = CreateThread( NULL, 0, z.y, 0, 0, &m_threadId );

It works but I am not real happy with a "smartass" solution like this.

Question? How can I recast a member function so I don't have to trick C++ into a funny union "cast"? (For C++ purists, my apologies. I'm an old, unreformed assembler and C hacker!)

GeneralRe: Casting thread functions Pin
Tim Deveaux24-Feb-01 3:57
Tim Deveaux24-Feb-01 3:57 
GeneralRe: Casting thread functions Pin
Joe Moldovan24-Feb-01 9:32
Joe Moldovan24-Feb-01 9:32 
GeneralRe: Casting thread functions Pin
aes24-Feb-01 10:49
aes24-Feb-01 10:49 
GeneralRe: Casting thread functions Pin
Joe Moldovan24-Feb-01 14:34
Joe Moldovan24-Feb-01 14:34 
GeneralRe: Casting thread functions Pin
Tim Deveaux24-Feb-01 15:07
Tim Deveaux24-Feb-01 15:07 
GeneralRe: Casting thread functions Pin
Joe Moldovan24-Feb-01 18:21
Joe Moldovan24-Feb-01 18:21 
GeneralRe: Casting thread functions Pin
NormDroid25-Feb-01 5:41
professionalNormDroid25-Feb-01 5:41 
GeneralRe: Casting thread functions Pin
Tim Deveaux24-Feb-01 14:58
Tim Deveaux24-Feb-01 14:58 
GeneralRe: Casting thread functions Pin
Todd Wilson24-Feb-01 15:20
Todd Wilson24-Feb-01 15:20 
GeneralRe: Casting thread functions Pin
Tim Deveaux24-Feb-01 15:32
Tim Deveaux24-Feb-01 15:32 
GeneralRe: Casting thread functions Pin
Erik Funkenbusch26-Feb-01 12:55
Erik Funkenbusch26-Feb-01 12:55 
GeneralRe: Casting thread functions Pin
Todd Wilson26-Feb-01 13:13
Todd Wilson26-Feb-01 13:13 
GeneralRe: Casting thread functions Pin
Erik Funkenbusch26-Feb-01 13:32
Erik Funkenbusch26-Feb-01 13:32 
GeneralRe: Casting thread functions Pin
Joe Moldovan24-Feb-01 17:44
Joe Moldovan24-Feb-01 17:44 
GeneralRe: Casting thread functions Pin
Tim Deveaux25-Feb-01 5:13
Tim Deveaux25-Feb-01 5:13 
GeneralRe: Casting thread functions Pin
Erik Funkenbusch26-Feb-01 13:11
Erik Funkenbusch26-Feb-01 13:11 
GeneralRe: Casting thread functions Pin
Joe Moldovan26-Feb-01 19:45
Joe Moldovan26-Feb-01 19:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.