///////////////////////////////////////////////////////////////
// ThreadDemo.cpp文件#include <stdio.h>
#include <windows.h>// 线程函数
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
int i = 0;
while(i < 20)
{
printf(" I am from a thread, count = %d \n", i++);
}
return 0;
}int  main(int argc, char* argv[])
{
HANDLE hThread;
DWORD dwThreadId;

// 创建一个线程
hThread = ::CreateThread (
NULL, // 默认安全属性
NULL, // 默认堆栈大小
ThreadProc, // 线程入口地址(执行线程的函数)
NULL, // 传给函数的参数
0, // 指定线程立即运行
&dwThreadId); // 返回线程的ID号
                 问题在这里:dwThreadId没有确切的值,为什么能做参数呢?
printf(" Now another thread has been created. ID = %d \n", dwThreadId); // 等待新线程运行结束
::WaitForSingleObject (hThread, INFINITE);
::CloseHandle (hThread);
return 0;
}

解决方案 »

  1.   

    把新建的进程编号存入dwThreadId之中啊,你就可以查看了啊
      

  2.   

    是线程编号,写错了,本来就是空的。就好像一个函数要返回多个返回值光一个RETURN满足不了,那就直接放在参数里返回了
      

  3.   

    HANDLE CreateThread(
      LPSECURITY_ATTRIBUTES lpThreadAttributes,
      SIZE_T dwStackSize,
      LPTHREAD_START_ROUTINE lpStartAddress,
      LPVOID lpParameter,
      DWORD dwCreationFlags,
      LPDWORD lpThreadId
    );对于第二个参数 MSDN上解释
    dwStackSize 
    [in] Initial size of the stack, in bytes. The system rounds this value to the nearest page. If this parameter is zero, the new thread uses the default size for the executable. For more information如果是0, 则是默认大小,是NULL