I have been trying to implement a single thread operation internal to a dialog window in my windows app. I have been all over the net, including this site and found alot of great examples, but nothing seems to be working. I have successfully followed the tutorials from the windows links on this site for Win32 console examples and built the nifty program for threads using _beginthread(), but all attempts to apply API based code has failed
OS: windows XP
Compiler: MS Visual C++ 6.0 Standard
I created a new class derived from CWinThread successfully called Thread:
I edited the Thread.cpp file to include my pointers to the dialog window I want to start and monitor the thread responses:Code:#if !defined(AFX_THREAD_H__9BC5C079_E9F6_42A7_B471_1CA97CC15BB6__INCLUDED_) #define AFX_THREAD_H__9BC5C079_E9F6_42A7_B471_1CA97CC15BB6__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // Thread.h : header file // class VIEWER; //forward declaration to VIEWER dialog ///////////////////////////////////////////////////////////////////////////// // Thread thread class Thread : public CWinThread { DECLARE_DYNCREATE(Thread) protected: Thread(); // protected constructor used by dynamic creation // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(Thread) public: virtual BOOL InitInstance(); virtual int ExitInstance(); virtual int Run(); //}}AFX_VIRTUAL void setOwner(VIEWER* ptrDialog) { ptrDlg = ptrDialog; } private: VIEWER* ptrDlg; //the pointer to pointer to object dialog window: VIEWER // Implementation protected: virtual ~Thread(); //protected destructor // Generated message map functions //{{AFX_MSG(Thread) // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_THREAD_H__9BC5C079_E9F6_42A7_B471_1CA97CC15BB6__INCLUDED_)
Then I create a handle object in the dialog window, VIEWER, I want to initate the thread in:Code:// Thread.cpp : implementation file // #include "stdafx.h" #include "FXG.h" #include "Thread.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // Thread IMPLEMENT_DYNCREATE(Thread, CWinThread) Thread::Thread() :ptrDlg(NULL) { } Thread::~Thread() { ptrDlg = NULL; } BOOL Thread::InitInstance() { // TODO: perform and per-thread initialization here return TRUE; } int Thread::ExitInstance() { // TODO: perform any per-thread cleanup here return CWinThread::ExitInstance(); } BEGIN_MESSAGE_MAP(Thread, CWinThread) //{{AFX_MSG_MAP(Thread) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // Thread message handlers int Thread::Run() { // TODO: Add your specialized code here and/or call the base class return CWinThread::Run(); }
Then I go into my InitDialog function to add my call to _beginthreadex() since I want to start the thread as soon as the dialog is called:Code:HANDLE hThread;
And I get the following errors returned:Code://assign handle object to equal call to begin thread and pass //in argurments for Thread::Run() hThread=(HANDLE)_beginthreadex(NULL,0,Thread::Run,this,0,0);
[cde]
C:\ASE\FXG\VIEWER.cpp(79) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'int (__thiscall Thread::*)(void)' to 'unsigned int (__stdcall *)(void *)'
There is no context in which this conversion is possible
[/code]
Please help, I have tried 15 different example programs, and been reading for days and not been able to solve the issue. BUT to be positive, I have learned alot that from my research, but I could use some assistance to get this resolved. Thanks again-



LinkBack URL
About LinkBacks



CornedBee