主题:[讨论]指向结构的变量和结构变量到底有什么差别?
代码一:
#include<iostream>
#include<windows.h>
int main(int argc,char* argv[])
{
using namespace std;
char* szCommandLine = "cmd";
STARTUPINFO si = {sizeof(si)};
[color=FF00FF]PROCESS_INFORMATION pi;[/color]
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE;
BOOL bRet = ::CreateProcess(
NULL, // name of executable module
szCommandLine, // command line string
NULL, // SD
NULL, // SD
FALSE, // handle inheritance option
CREATE_NEW_CONSOLE, // creation flags
NULL, // new environment block
NULL, // current directory name
&si, // startup information
[color=FF00FF]π[/color]// process information
);
if(bRet)
{
::CloseHandle([color=FF00FF]pi.hThread[/color]);
::CloseHandle([color=FF00FF]pi.hProcess[/color]);
cout << "新进程的进程ID号" <<[color=FF00FF]pi.dwProcessId[/color]) << endl;
cout << "新进程的主线程ID号" <<<<[color=FF00FF]pi.dwThreadId [/color]<< endl;
}
return 0;
}
代码二:
#include<iostream>
#include<windows.h>
int main(int argc,char* argv[])
{
using namespace std;
char* szCommandLine = "cmd";
STARTUPINFO si = {sizeof(si)};
[color=FF00FF]LPPROCESS_INFORMATION pi;[/color]
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE;
BOOL bRet = ::CreateProcess(
NULL, // name of executable module
szCommandLine, // command line string
NULL, // SD
NULL, // SD
FALSE, // handle inheritance option
CREATE_NEW_CONSOLE, // creation flags
NULL, // new environment block
NULL, // current directory name
&si, // startup information
[color=FF00FF]pi[/color]// process information
);
if(bRet)
{
::CloseHandle([color=FF00FF]pi->hThread[/color]);
::CloseHandle([color=FF00FF]pi->hProcess[/color]);
cout << "新进程的进程ID号" << [color=FF00FF]pi->dwProcessId[/color] << endl;
cout << "新进程的主线程ID号" <<[color=FF00FF]pi->dwThreadId [/color]<< endl;
}
return 0;
}
为什么不能将pi声明为LPPROCESS_INFORMATION ,而只能声明为PROCESS_INFORMATION,LPPROCESS_INFORMATION 是指向结构的指针,而PROCESS_INFORMATION就是一个结构,为什么第一个可以有结果,而第二个代码能通过编译,但是运行弹不出新建的控制台呢?
#include<iostream>
#include<windows.h>
int main(int argc,char* argv[])
{
using namespace std;
char* szCommandLine = "cmd";
STARTUPINFO si = {sizeof(si)};
[color=FF00FF]PROCESS_INFORMATION pi;[/color]
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE;
BOOL bRet = ::CreateProcess(
NULL, // name of executable module
szCommandLine, // command line string
NULL, // SD
NULL, // SD
FALSE, // handle inheritance option
CREATE_NEW_CONSOLE, // creation flags
NULL, // new environment block
NULL, // current directory name
&si, // startup information
[color=FF00FF]π[/color]// process information
);
if(bRet)
{
::CloseHandle([color=FF00FF]pi.hThread[/color]);
::CloseHandle([color=FF00FF]pi.hProcess[/color]);
cout << "新进程的进程ID号" <<[color=FF00FF]pi.dwProcessId[/color]) << endl;
cout << "新进程的主线程ID号" <<<<[color=FF00FF]pi.dwThreadId [/color]<< endl;
}
return 0;
}
代码二:
#include<iostream>
#include<windows.h>
int main(int argc,char* argv[])
{
using namespace std;
char* szCommandLine = "cmd";
STARTUPINFO si = {sizeof(si)};
[color=FF00FF]LPPROCESS_INFORMATION pi;[/color]
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE;
BOOL bRet = ::CreateProcess(
NULL, // name of executable module
szCommandLine, // command line string
NULL, // SD
NULL, // SD
FALSE, // handle inheritance option
CREATE_NEW_CONSOLE, // creation flags
NULL, // new environment block
NULL, // current directory name
&si, // startup information
[color=FF00FF]pi[/color]// process information
);
if(bRet)
{
::CloseHandle([color=FF00FF]pi->hThread[/color]);
::CloseHandle([color=FF00FF]pi->hProcess[/color]);
cout << "新进程的进程ID号" << [color=FF00FF]pi->dwProcessId[/color] << endl;
cout << "新进程的主线程ID号" <<[color=FF00FF]pi->dwThreadId [/color]<< endl;
}
return 0;
}
为什么不能将pi声明为LPPROCESS_INFORMATION ,而只能声明为PROCESS_INFORMATION,LPPROCESS_INFORMATION 是指向结构的指针,而PROCESS_INFORMATION就是一个结构,为什么第一个可以有结果,而第二个代码能通过编译,但是运行弹不出新建的控制台呢?