views:

353

answers:

3

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 GetModuleFileName to get the file name. Im wondering if there is an equivalent method to get the args.

+7  A: 

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.

Brian R. Bondy
Hmm, that's GetCommandLine
EFraim
Fixed the link name, thanks.
Brian R. Bondy
Thanks, I was having troubles finding this.
Zenox
+3  A: 

That's platform specific.

In Win32 you can use GetCommandLine().

You will have to do the parsing manually, though.

EFraim
+1 thx for correction
Brian R. Bondy
+1  A: 

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.

jmucchiello