我發現一個程式 呼叫另一個程式時,傳入的引數argv[0] ,不是程式路徑。而是一個普通的引數 【-i】
怎么才能實作這樣的呼叫,其它exe?
uj5u.com熱心網友回復:
可以在命令列啟動你已經編譯好的exe檔案,在后面帶傳入的引數,或者用win32提供的創建行程的api啟動你的程式,傳入所需要的引數uj5u.com熱心網友回復:
// argv.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include <string.h>
#include <tchar.h>
int main(int argc, char* argv[])
{
printf("%s\n", argv[ 0 ]);
TCHAR exe[ 0x200 ];
_tcscpy( exe, argv[ 0 ] );
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwFlags |= STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWDEFAULT;
ZeroMemory( &pi, sizeof( pi ) );
if( !CreateProcess( exe, // No module name (use command line).
_T( "\r\n-i----------------------" ), // 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.
)
{
//AfxMessageBox( _T( "Update failure" ) );
return 0;
}
return 0;
}
試了一下,自己呼叫自己,被呼叫的argv[ 0 ],傳什么都行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/136535.html
標籤:進程/線程/DLL
