怎么用CREATTHREAD,创建线程??能在不用MFC而纯C/C++的环境中用吗?要包含什么头文件?具体怎么操作,稍微讲一下好吗?弄懂后马上给分!
解决方案 »
- 为什么不能够引用第二个自动化类
- 我用vc怎么连接远程的SQL数据库?新手问题
- 异常退出
- Atl制作com组件,使用socket的奇怪问题,Up有分!!
- VC简单问题
- 我现在有2组RADIO,每组3个RADIO控件,怎么使这2组RADIO在同一个对话框里各自管各自选择?
- 结束线程后还要做些什么
- 请问在TC下的源文件如何在VC++中编译?
- 在windows 2000 server 下怎么启动faxService服务?
- directshow的memfiles例子在什么地方?
- 高分求助window2000下的串口通讯模块!
- 我的---关于在VC6.0中开发多国语言显示问题的总结---(有源码作为部分参考)
#include <windows.h>see examples athttp://codeguru.earthweb.com/system/OOThreadWrapper.htmlhttp://codeguru.earthweb.com/dll/DLL_Callback.html
also see
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0799/win32/win320799.htm&nav=/msj/0799/newnav.htm
#include <iostream>using namespace std;void WINAPI f(LPVOID pvThread)
{
cout << "inside thread" << endl;
}int main()
{
cout << "inside main" << endl;
HANDLE hThread = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)f,
NULL,
0,
NULL); if(hThread != NULL)
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
return 0;
}
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
是做什么的呢
4:(LPTHREAD_START_ROUTINE)f 是不是把相应的函数与相应的线程结合起来? 谢谢
#define WINAPI __stdcallthis is the calling convention, but it is not needed in this case3. the main thread waits until the child thread finishes4. it just casts the function pointer into the required signaturetypedef DWORD (WINAPI * PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;to be strict, you should be doingDWORD WINAPI f(LPVOID pvThread)
{
cout << "inside thread" << endl;
return 0;
}
怎么就是不出来inside thread?
一上来就出现inside main
是不是不需要
if(hThread != NULL)
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
?我怎么试(无论是在线程里加断点还是别的,)就是不出现inside thread
late a night(actually in so early a day)
Setting environment for using Microsoft Visual C++ tools.
D:\TEMP>cl testmt.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.testmt.cpp
.........
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved./out:testmt.exe
testmt.objD:\TEMP>testmt
inside main
inside threadD:\TEMP>
work here--win98.
really thank u!!