开发者

C++ Access to command line arguments outside main?

I have a couple command line apps that both end up calling into com objects. Rather than adding new interface to these com objects, can they access the parameters passed from the command line?

Edit: Sort of how I can call GetM开发者_StackOverflowoduleFileName to get the file name. Im wondering if there is an equivalent method to get the args.


The Win32 API that you're looking for is: GetCommandLine.

Your COM object probably needs to run within your process though.

To convert the command line to an argv style array of strings, call the CommandLineToArgvW function.


That's platform specific.

In Win32 you can use GetCommandLine().

You will have to do the parsing manually, though.


In Windows you can get the command line with a WIN32 function (GetCommandLine) call but it won't be parsed into an array like argc/argv. If the COM object uses MFC you can get the command line arguments from your CWinApp object. Otherwise, there's no easy way to do it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜