衡玉's Blog

Happy coding

MFC的dll中创建子线程,并发送消息

衡玉 posted @ 2010年2月21日 22:50 in windows 服务编程 , 2957 阅读

 ATL创建的windows服务,只是负责控制,而将业务逻辑放在mfc的dll中,建立线程后,在发送消息,代码如下

 

extern "C" __declspec(dllexport) void _DllMain()
{
	unsigned nThreadId;
	HANDLE hThread = (HANDLE)_beginthreadex(NULL,0, &ThreadMain,NULL, 0, &nThreadId);
	Sleep(1000);
	PostThreadMessage(nThreadId, WM_TIMEISUP, NULL, NULL);
}

unsigned __stdcall ThreadMain(LPVOID pParam)
{
	MSG msg;
	while(true){
		if(::GetMessage(&msg, NULL, NULL, NULL)) {
			switch(msg.message){
				case WM_TIMEISUP:
				{
					Download d;
					break;
				}
				default:
					break;
			}
		}
	};
	
	/*
	MSG msg;
	while(::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
		switch(msg.message) {
			case WM_TIMEISUP:
			{
				Download d;
				break;
			}
			default:
				break;
		}
	}*/
	return 0;
}

 

 

Avatar_small
Uttarakhand Board Qu 说:
2022年8月29日 21:15

UK Board 10th Previous Question Paper are very important for the Preparation of Public Exam of UBSE for the Students. 10th Students of can easily get their Latest and most valuable Mock Test Paper from this website. Uttarakhand Board Question Paper Students only have to Download the UBSE 10th Mock Test Paper 2023 for all the important subjects are available Including the Hindi, English, Social Science, Mathematics, Science, Home Science, Sanskrit, Painting etc. Boardmodelpaper.com Provide UBSE Board 10th Class Latest and Last Year Exam Study Material for Syllabus, Question Paper etc, Hindi, English Medium Pdf Format.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter