主题:新手请教
void CmyIDEDlg::OnBnClickedOk()
{
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if (!CreatePipe(&hRead,&hWrite,&sa,0)) {
AfxMessageBox("Error On CreatePipe()");
return;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
if (!CreateProcess(NULL,"cl c:\\111.cpp"
,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) {
AfxMessageBox("Error on CreateProcess()");
return;
}
CloseHandle(hWrite);
char buffer[4096] = {0};
DWORD bytesRead;
while (true) {
if (ReadFile(hRead,buffer,4095,&bytesRead,NULL) == NULL)
break;
m_edit1 += buffer;
UpdateData(false);
Sleep(200);
}
我的目的是用CMD命令调用VS的cl.exe来编译一个文件,然后在对话框显示编译结果,但显示结果是这样的111.cpp
.08 版
D:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
/out:111.exe
111.obj
LINK : fatal error LNK1104: 无法打开文件“kernel32.lib”
我自己手动设置环境变量也不可以 ,我在DOS下试了,必须先显示使用下VCVARS32.BAT,然后用cl 111.cpp才可以生成exe文件,现在我想在程序里实现,请高手指教下,给个思路也行。
{
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if (!CreatePipe(&hRead,&hWrite,&sa,0)) {
AfxMessageBox("Error On CreatePipe()");
return;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
if (!CreateProcess(NULL,"cl c:\\111.cpp"
,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) {
AfxMessageBox("Error on CreateProcess()");
return;
}
CloseHandle(hWrite);
char buffer[4096] = {0};
DWORD bytesRead;
while (true) {
if (ReadFile(hRead,buffer,4095,&bytesRead,NULL) == NULL)
break;
m_edit1 += buffer;
UpdateData(false);
Sleep(200);
}
我的目的是用CMD命令调用VS的cl.exe来编译一个文件,然后在对话框显示编译结果,但显示结果是这样的111.cpp
.08 版
D:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
/out:111.exe
111.obj
LINK : fatal error LNK1104: 无法打开文件“kernel32.lib”
我自己手动设置环境变量也不可以 ,我在DOS下试了,必须先显示使用下VCVARS32.BAT,然后用cl 111.cpp才可以生成exe文件,现在我想在程序里实现,请高手指教下,给个思路也行。