這是「sleeper.exe」的源代碼,我有:參數傳遞到可執行文件無法工作在C++
int main(int argc, char** argv) {
cout<<argv[1];
return 0;
}
當我從命令行調用是這樣的:
C:\sleeper 5
我見
5
在命令行
所以這個工作得很好..
現在,我想打電話給一些其他的EXE此exe是這樣的:
std::cout << "ret is:" << ret;
std::cout << "\n";
CreateProcess("sleeper.exe", // No module name (use command line)
ret, // 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
)
這裏RET是5,以及,我相信,因爲我看到它在命令行罰款:
ret is: 5
有一個名爲config.mpap在同一個目錄下的文件和我讀值從這裏開始是這樣的:
std::ifstream myReadFile;
myReadFile.open("config.mpap");
char output[400];
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
}
}
myReadFile.close();
char y = output[37];
int numberOfSleeps = y - '0'; // So now numberOfSleeps is 5
然後我轉換numberOfSleeps到RET這樣的:
char* ret = NULL;
int numChars = 0;
bool isNegative = false;
// Count how much space we will need for the string
int temp = sleepTime;
do {
numChars++;
temp /= 10;
} while (temp);
ret = new char[ numChars + 1 ];
ret[numChars] = 0;
if (isNegative) ret[0] = '-';
int i = numChars - 1;
do {
ret[i--] = sleepTime % 10 + '0';
sleepTime /= 10;
} while (sleepTime);
可以請別人幫我,爲什麼RET不通過從createprocess.exe到sleeper.exe?
編輯:
它的工作原理是這樣的:
if (!CreateProcess(NULL, // No module name (use command line)
"sleeper 5", // Command line
然而,這並不甚至編譯:
std::string sleeper("sleeper ");
sleeper += ret;
if (!CreateProcess(NULL, // No module name (use command line)
sleeper, // Command line
@NicholasM [CreateProcess](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v = vs.85).aspx)是一個WINAPI函數。因此操作系統將成爲Windows。他不能複製它,因爲它是原生的。 – Kiruse
@ Derija93,謝謝,我會刪除我的評論。 – NicholasM
出於好奇,你在控制檯中看到了什麼? – Kiruse