Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ Pointer
Hi friends,
 
I am new in c++ programming. Can anybody explain me the meaning of below statements.
unsigned long __stdcall CPlaybackDlg::ControlExecuteThreadEntry(void *pParent)
{
	CPlaybackDlg *pTmp = (CPlaybackDlg*)pParent;
}
where CPlaybackDlg is derived from CDialog.
 
Thanx in advance
Posted 7-Jan-13 23:41pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

CPlaybackDlg *pTmp = (CPlaybackDlg*)pParent;
 
That is a C-like cast of a void pointer to a CPlaybackDlg object one.
 
With such a statement you are telling to the compiler: "I know what I am doing: I know that pParent in spite of being a void * is really a PlaybackDlg*, hence you have to handle it consequently".
 
Such a idiom is frequently used for passing parameter to thread functions (see, for instance this MSDN example[^]).
  Permalink  
v3
Comments
Mohibur Rashid at 8-Jan-13 22:16pm
   
Excellent one
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi,
the pParent is a void pointer i.e. a pointer which can point to objects of any type.The void pointer does not know what type of object it is pointing to, so the void pointer must first be explicitly cast to another pointer type before it can be dereferenced.
 
And you want a pointer pTmp of type CPlaybackDlg which should point at the same object as pParent . So pParent is typecast to type CPlaybackDlg by placing (CPlaybackDlg*) in front of it and this typecast is used to initialize pTmp .
 
know more about void pointers here[^]
some info on typecasting here[^]
 
hope this helps .
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Also be aware that if you don't do anything with the pointer, nothing useful happens in this method. It is like doing
 
void blah()
{
  int doNothing = 42;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140826.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100