sdk中使用cevent类
本帖最后由 chenhui1990421 于 2013-10-12 16:50:37 编辑
#define _WIN32_WINNT 0x0502
#include <afxmt.h>
#define _WIN32_WINNT 0x0502
#include <stdio.h>
DWORD WINAPI myfun1(//声明线程函数
LPVOID lpParameter
);
DWORD WINAPI myfun2(
LPVOID lpParameter
);
int a=0;
CEvent event;//定义全局变量a
int main()
{
event=CEvent(false,false,NULL,NULL);
printf("事件对象\r\n");
HANDLE h1,h2;//定义线程句柄
//event.m_hObject =::CreateEvent(NULL,FALSE,false,NULL);
event.SetEvent();
h1=::CreateThread(NULL,0,myfun1,NULL,0,NULL);//创建线程1
printf("线程1开始运行!\r\n");
h2=::CreateThread(NULL,0,myfun2,NULL,0,NULL);//创建线程2
printf("线程2开始运行!\r\n");
::CloseHandle(h1);//关闭线程句柄对象
::CloseHandle(h2);
::Sleep(100000);//程序睡眠10秒
return 0;
}
运行之后出现:
使用mfc的CEvent类编程.obj : error LNK2019: 无法解析的外部符号 "public: class CEvent & __thiscall CEvent::operator=(class CEvent const &)" (??4CEvent@@QAEAAV0@ABV0@@Z),该符号在函数 _main 中被引用,E:\Windows 网络编程\Win32 网络编程\Debug\多线程与异步套接字.exe : fatal error LNK1120: 1 个无法解析的外部命令
这是怎么回事,我按照网上说的修改为使用--在共享dll使用mfc,以及c++链接中使用多线程。
请大神赐教啊!感激不尽!!! sdk 网络编程 多线程 class
[解决办法]
都说SDK了你还用神马 CEVENT
使用: CreateEvent SetEvent WaitForSingleObject
CSyncEvent::CSyncEvent(bool bManualReset,bool bInitialState)
{
m_handle=::CreateEvent(NULL,(BOOL)bManualReset,(BOOL)bInitialState,NULL);
}
CSyncEvent::~CSyncEvent(void)
{
if( m_handle )
{
::CloseHandle(m_handle);
}
}
void CSyncEvent::SetEvent()
{
::SetEvent(m_handle);
}
void CSyncEvent::ResetEvent()
{
::ResetEvent(m_handle);
}
bool CSyncEvent::Wait(int nTime)
{
return WAIT_OBJECT_0 == ::WaitForSingleObject(m_handle,nTime);
}
[解决办法]
CEvent event(false,false,NULL,NULL);