我在VC 建立了Win32 Appication工程 ,程序如下:
#include
#include
#include
#include
#include
#include
class CmyEvent
{
private:
HANDLE m_hEvent;
public:
//constructor
CmyEvent(BOOL bAuto,char* EventName);
//impleation
//wait for a event
unsigned long WaitForEvent(double time);
//set a event
BOOL Signal();
//reset a event
BOOL Reset();
//pulse a event
BOOL Pulse();
//check the state of a event
BOOL IsSignaled();
};
CmyEvent:: CmyEvent(BOOL bAuto,char* EventName)
{
m_hEvent=::CreateEvent(NULL,bAuto,FALSE,NULL);
// if(NULL==m_hEvent)
// AfxMessageBox("Fail");
}
unsigned long CmyEvent::WaitForEvent(double time)
{
return ::WaitForSingleObject(m_hEvent,(DWORD)time);
}
BOOL CmyEvent::Signal()
{
return ::SetEvent(m_hEvent);
}
BOOL CmyEvent::Reset()
{
return ::ResetEvent(m_hEvent);
}
BOOL CmyEvent::Pulse()
{
return ::PulseEvent(m_hEvent);
}
/*
BOOL CmyEvent::Pulse()
{
::SetEvent(m_hEvent);
::Sleep(100);
::ResetEvent(m_hEvent);
return TRUE;
}
*/
BOOL CmyEvent::IsSignaled()
{
BOOL flag=false;
if(::WaitForSingleObject(m_hEvent,0)==WAIT_OBJECT_0)
flag=true;
}
CmyEvent Myevent(TRUE,"MYEVENT");
int array[5];
void MyThread1(void* arg)
{
Sleep(2000);
for(int i=0;i<5;i++)
array[i]=i;
cout<<"Data are ready.Signal an event!"< Myevent.Signal();
}
void MyThread2(void* arg)
{
cout<<"Data are ready.Get signaled!"< for(int i=0;i<5;i++)
cout<}
int main(int argc, char* argv[])
{
_beginthread(MyThread1,0,NULL);
_beginthread(MyThread2,0,NULL);
Sleep(6000);
return 0;
}
可是编译时说:D:\VC\Demo\demo.cpp(95) : error C2065: '_beginthread' : undeclared identifier
可是_beginthread是windows 的API函数啊,怎么会是undeclared identifier
呢?
--------------------next---------------------
阅读(1604) | 评论(0) | 转发(0) |