开发者

How does Windows pass arguments to a program? (And is there a SetCommandLine function?)

开发者 https://www.devze.com 2023-02-20 08:20 出处:网络
How does the entry开发者_开发知识库 point receive arguments from the command line? I looked through a disassembly of one and found it calls __getmainargs to obtain the arguments. Is there a way to \"_

How does the entry开发者_开发知识库 point receive arguments from the command line? I looked through a disassembly of one and found it calls __getmainargs to obtain the arguments. Is there a way to "__setmainargs"? I know that CreateProcess does this already but I want to see how CreateProcess does this


AFAIK the arguments are passed as a single string in memory, so in truth there is just ONE argument - the splitting into several is done by your program. The Kernel receives the argument from the CreateProcess() call and places it in a predefined memory location when setting up the new process.

But that is just my half-educated guess.


At a Win32 level, the application will call GetCommandLine() at some point to retrieve the command line that was given to the CreateProcess() call. There is no corresponding SetCommandLine call, so after a new process is launched there is no way to "change" its command line arguments.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号