//
/*
有如下警告,能不能稍微修改,使之不出现警告?
Compiling...
StdAfx.cpp
Compiling...
CreateThread.cpp
F:\VC6.0\MULTITHREAD\CreateThread\CreateThread.cpp(18) : warning C4700: local variable 'exitCode' used without having been initialized
F:\VC6.0\MULTITHREAD\CreateThread\CreateThread.cpp(29) : warning C4700: local variable 'exitCode' used without having been initialized
Linking...
CreateThread.exe - 0 error(s), 2 warning(s)
*/
#include "stdafx.h"
#include<iostream.h>
#include<process.h>//CreateThread(),ExitThread() and CloseHandle()
#include<windows.h>
#include<stdio.h>
BOOL repeat=TRUE;
DWORD WINAPI MyThread1(LPVOID lpParameter)
{
while(repeat)
{
printf("How are you?\n");
Sleep(1);
}
DWORD exitCode;//有问题的地方
ExitThread(exitCode);
return 0;
}
DWORD WINAPI MyThread2(LPVOID lpParameter)
{
while(repeat)
{
printf("Very well!\n");
Sleep(1);
}
DWORD exitCode;//有问题的地方
ExitThread(exitCode);
return 0;
}
DWORD WINAPI KillThread(LPVOID lpParameter)
{
repeat=FALSE;
return 0;
}
int main(int argc, char* argv[])
{
HANDLE handle1,handle2,handle3;
DWORD dw1,dw2,dw3;
handle1=CreateThread(NULL,0,MyThread1,NULL,0,&dw1);
if(handle1==NULL)
{
printf("Create Thread 1 Failed!\n");
return -1;
}
handle2=CreateThread(NULL,0,MyThread2,NULL,0,&dw2);
if(handle2==NULL)
{
printf("Create Thread 2 Failed!\n");
return -1;
}
Sleep(1000);
handle3=CreateThread(NULL,0,KillThread,NULL,0,&dw3);
if(handle3==NULL)
{
printf("Create Thread 3 Failed!\n");
return -1;
}
CloseHandle(handle1);
CloseHandle(handle2);
CloseHandle(handle3);
return 0;
}
5 个解决方案
#1
DWORD exitCode = 0;
#2
BOOL GetExitCodeThread( HANDLE hThread,LPDWORD lpExitCode);
hThread是线程的handle,
lpExitCode 返回一个ExitCode
然后 ExitThread(exitCode);
hThread是线程的handle,
lpExitCode 返回一个ExitCode
然后 ExitThread(exitCode);
#3
变量没有初始化,赋个初值就可以了!
#4
DWORD exitCode;//有问题的地方
ExitThread(exitCode);
当然会被警告了,刚声明完就拿来用,谁给他置上状态。
ExitThread(exitCode);
当然会被警告了,刚声明完就拿来用,谁给他置上状态。
#5
exitCode还没有值啊,
就象int n; printf("%d",n);
就象int n; printf("%d",n);
#1
DWORD exitCode = 0;
#2
BOOL GetExitCodeThread( HANDLE hThread,LPDWORD lpExitCode);
hThread是线程的handle,
lpExitCode 返回一个ExitCode
然后 ExitThread(exitCode);
hThread是线程的handle,
lpExitCode 返回一个ExitCode
然后 ExitThread(exitCode);
#3
变量没有初始化,赋个初值就可以了!
#4
DWORD exitCode;//有问题的地方
ExitThread(exitCode);
当然会被警告了,刚声明完就拿来用,谁给他置上状态。
ExitThread(exitCode);
当然会被警告了,刚声明完就拿来用,谁给他置上状态。
#5
exitCode还没有值啊,
就象int n; printf("%d",n);
就象int n; printf("%d",n);