这是我的程序:有很多类似'STARTUPINFOW' : undeclared identifier的错误,我已经把头文件都加进去?为什么会有这个错误?请问怎么改啊?谢谢!
#include"iostream"
#include"windows.h"
#include"winbase.h"
#include "stdafx.h"int main(int argc,char*argv[])
{
char szCommandLine[]="cmd";
STARTUPINFOW si={sizeof(si)};
PROCESS_INFORMATION pi;
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=TRUE; BOOL bRet=::CreateProcess(
NULL,
szCommandLine,
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);
if(bRet)
{
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
printf("新的进程的进程ID号:%d\n",pi.dwProcessId);
printf("新的进程的主线程ID号:%d\n",pi.dwThreadId);
}
return 0;
}c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2065: 'STARTUPINFOW' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2146: syntax error : missing ';' before identifier 'si'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2065: 'si' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2059: syntax error : '{'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2070: ''unknown-type'': illegal sizeof operand
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(10) : error C2065: 'PROCESS_INFORMATION' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(10) : error C2146: syntax error : missing ';' before identifier 'pi'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(10) : error C2065: 'pi' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(11) : error C2228: left of '.dwFlags' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(11) : error C2065: 'STARTF_USESHOWWINDOW' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(12) : error C2228: left of '.wShowWindow' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(12) : error C2065: 'TRUE' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2065: 'BOOL' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2146: syntax error : missing ';' before identifier 'bRet'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2065: 'bRet' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2039: 'CreateProcess' : is not a member of '`global namespace''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(19) : error C2065: 'FALSE' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(20) : error C2065: 'CREATE_NEW_CONSOLE' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C3861: 'CreateProcess': identifier not found
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(27) : error C2039: 'CloseHandle' : is not a member of '`global namespace''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(27) : error C2228: left of '.hThread' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(27) : error C3861: 'CloseHandle': identifier not found
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(28) : error C2228: left of '.hProcess' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(29) : error C2228: left of '.dwProcessId' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(30) : error C2228: left of '.dwThreadId' must have class/struct/union
type is ''unknown-type''
生成日志保存在“file://c:\Documents and Settings\lichangqing\My Documents\Visual Studio 2005\创建进程\创建进程\Debug\BuildLog.htm”
创建进程 - 27 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
#include"iostream"
#include"windows.h"
#include"winbase.h"
#include "stdafx.h"int main(int argc,char*argv[])
{
char szCommandLine[]="cmd";
STARTUPINFOW si={sizeof(si)};
PROCESS_INFORMATION pi;
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=TRUE; BOOL bRet=::CreateProcess(
NULL,
szCommandLine,
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);
if(bRet)
{
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
printf("新的进程的进程ID号:%d\n",pi.dwProcessId);
printf("新的进程的主线程ID号:%d\n",pi.dwThreadId);
}
return 0;
}c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2065: 'STARTUPINFOW' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2146: syntax error : missing ';' before identifier 'si'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2065: 'si' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2059: syntax error : '{'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2070: ''unknown-type'': illegal sizeof operand
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(9) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(10) : error C2065: 'PROCESS_INFORMATION' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(10) : error C2146: syntax error : missing ';' before identifier 'pi'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(10) : error C2065: 'pi' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(11) : error C2228: left of '.dwFlags' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(11) : error C2065: 'STARTF_USESHOWWINDOW' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(12) : error C2228: left of '.wShowWindow' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(12) : error C2065: 'TRUE' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2065: 'BOOL' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2146: syntax error : missing ';' before identifier 'bRet'
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2065: 'bRet' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C2039: 'CreateProcess' : is not a member of '`global namespace''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(19) : error C2065: 'FALSE' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(20) : error C2065: 'CREATE_NEW_CONSOLE' : undeclared identifier
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(14) : error C3861: 'CreateProcess': identifier not found
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(27) : error C2039: 'CloseHandle' : is not a member of '`global namespace''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(27) : error C2228: left of '.hThread' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(27) : error C3861: 'CloseHandle': identifier not found
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(28) : error C2228: left of '.hProcess' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(29) : error C2228: left of '.dwProcessId' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\lichangqing\my documents\visual studio 2005\创建进程\创建进程\a.cpp(30) : error C2228: left of '.dwThreadId' must have class/struct/union
type is ''unknown-type''
生成日志保存在“file://c:\Documents and Settings\lichangqing\My Documents\Visual Studio 2005\创建进程\创建进程\Debug\BuildLog.htm”
创建进程 - 27 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
#include <windows.h>int main(int argc,char*argv[])
{
char szCommandLine[]="cmd";
STARTUPINFO si={sizeof(si)};
PROCESS_INFORMATION pi;
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=TRUE;BOOL bRet=::CreateProcess(
NULL,
szCommandLine,
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);
if(bRet)
{
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
printf("新的进程的进程ID号:%d\n",pi.dwProcessId);
printf("新的进程的主线程ID号:%d\n",pi.dwThreadId);
}
return 0;
} 在我的机器上,编译通过
#include "stdafx.h"
#include"windows.h"
#include "winbase.h"似乎和头文件的顺序有关。#include "stdafx.h"这个是生成的项目自带的!
2,还把
char szCommandLine[]="cmd";
改为 tchar szCommandLine[]=text("cmd");
据查是因为宽字符类型与单字符类型的区别。不知五岭散人是生成的什么工程?为什么咱俩的头文件不一样,还都能运行?
据查:CREATE_NEW_CONSOLE是在winbase.h中定义的,你的头文件中为什么不用包含它?再次谢谢五岭散人!!
不是STARTUPINFOW 是STARTUPINFO,
注意最后的W
能否告知原因 [email protected] 。。
你在 项目——》 属性里——》 配置属性——》把【使用Unicode字符集】 改成【使用多字节字符集】
就OK了