因为一些原因必须要兼容 xp 系统,在 win7 64 位 win10 64 位都没问题
编译环境:vs2019,工具集 v141_xp, crt 版本:14.16.27023, mt release (用 vs2010 的 crt 编译好像没有问题)
代码如下:
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#include <tchar.h>
#include <process.h>
unsigned int __stdcall ThreadDemo(LPVOID lpThreadParameter)
{
char str[10000] = { 'a','s','d','f','\0' };
OutputDebugStringA(str);
_endthreadex(0);
return 0;
}
void thread()
{
HANDLE h = (HANDLE)_beginthreadex(NULL, 0, ThreadDemo, NULL, 0, NULL);
if (h)
{
WaitForSingleObject(h, INFINITE);
CloseHandle(h);
} }
int main()
{
while (true)
{
thread();
Sleep(1);
}
return 0;
}