GetLastError() 使用方法

#include 
#include 
using namespace std;

int main(int argc, char* argv[])
{
	STARTUPINFO si = { sizeof(si) };
	PROCESS_INFORMATION pi;

	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = TRUE;
	char szCommandLine[] = "cmd";
	BOOL bRet = CreateProcess(
		NULL,
		(LPWSTR)szCommandLine,
		NULL,
		NULL,
		FALSE,
		CREATE_NEW_CONSOLE,
		NULL,
		NULL,
		&si,
		&pi
	);
	int nError = GetLastError();
	if (bRet){
		cout << "进程的进程ID号:" << pi.dwProcessId << endl;
		cout << "进程的主线程ID号:" << pi.dwThreadId << endl;
		::CloseHandle(pi.hThread);
		::CloseHandle(pi.hProcess);
	}else{
		cout << "创建进程失败:" << nError << endl;
	}
	return 0;
}

GetLastError() 使用方法_第1张图片

 

你可能感兴趣的:(Windows编程,Windows原理)