CB6运行另一个程序用什么函数? - C++ Builder / Windows SDK/API
在CB6中运行另一个程序到底是用什么函数啊?
网上找的,有的说是用WinExec,有的说是用ShellExecute,还有就是用CreateProcess。
这3个函数在CB6中的帮助文档中找不到这样的函数,这3个函数各有什么不同呢?
各位高手,请指点下新手啊!
[解决办法]
- C/C++ code
//以系统Windows自带的计算器为例子//将计算器拷贝到自己的exe目录下,或者自己指定被调用exe的目录AnsiString ls_help=ExtractFilePath(Application->ExeName) +"calc.exe" ;ShellExecute(Handle,NULL,ls_help.c_str(),NULL,NULL,SW_SHOWNORMAL);
[解决办法]
- C/C++ code
#include <windows.h>#include <stdio.h>#include <tchar.h>void _tmain( VOID ){ STARTUPINFO si; PROCESS_INFORMATION pi; LPTSTR szCmdline=_tcsdup(TEXT("MyChildProcess")); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) szCmdline, // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { printf( "CreateProcess failed (%d).\n", GetLastError() ); return; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread );}
[解决办法]
打开外部程序我一般用 ShellExecute
打开系统内部自带的 我一般用WinExec