|
-
December 3rd, 2006, 01:34 PM
#1
Quick CWinThread Question please
Hi All...
Not being au fait with multi threading, Id just like to get your advice,
Im starting a thread like this:
Code:
m_pFileHub = AfxBeginThread(RUNTIME_CLASS(CFileHub),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
where m_pFileHub is a pointer to a class derived from CWinThread.
Now the compiler doesnt like it because it insists on returning a CWinThread*, not a CFileHub*.
My question is, how do I start my thread then get access to its variables and methods. I had thought I would be able to use the pointer returned by AfxBeginThread !
Thanks all for helping me
Phill
-
December 3rd, 2006, 02:18 PM
#2
Re: Quick CWinThread Question please
[ removed duplicate thread ]
[ Moved thread ]
-
December 3rd, 2006, 02:24 PM
#3
Re: Quick CWinThread Question please
Just cast the returned pointer like:
Code:
m_pFileHub = (CFileHub*)AfxBeginThread(RUNTIME_CLASS(CFileHub),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
-
December 3rd, 2006, 02:51 PM
#4
Re: Quick CWinThread Question please
Or use the C++ style static_cast operator:
Code:
m_pFileHub = static_cast<CFileHub*>(AfxBeginThread(RUNTIME_CLASS(CFileHub),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED));
- petter
-
December 3rd, 2006, 03:28 PM
#5
Re: Quick CWinThread Question please
Thanks Guys !
Wildfrog, like the solution.. neat !
Incidently Im trying to call ::Create against a CDialog* in a function in the Threaded class.
The compiler is having non of it.
during this call:
Code:
m_pProgressDialog->Create(IDD_PROGRESS_DIALOG);
I get an ASSERTION in DLGCORE>CPP here:
Code:
BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
ASSERT(HIWORD(lpszTemplateName) == 0 ||
AfxIsValidString(lpszTemplateName));
--> --> m_lpszTemplateName = lpszTemplateName; // used for help
if (HIWORD(m_lpszTemplateName) == 0 && m_nIDHelp == 0)
m_nIDHelp = LOWORD((DWORD)m_lpszTemplateName);
#ifdef _DEBUG
if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))
Is there any reason why I cant do this in a class derived from CWinThread ?
Thanks
Phil
Last edited by Phill Heald; December 3rd, 2006 at 03:59 PM.
-
December 4th, 2006, 04:46 PM
#6
Re: Quick CWinThread Question please
Did you create it as a "GUI" type thread? There are two types of threads worker threads, and GUI threads:
http://msdn2.microsoft.com/en-us/lib...z9(VS.71).aspx
There's an example project on that page that might help you out (I haven't looked at the example myself).
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|