Skip to navigation
   
Dave F's Blog
Re-inventing the wheel, argv / argc in windows

By Dave F in Reader

Posted in Coding, Microsoft on August 10, 2009 at 3:48 pm

Permalink | Author Profile

I had to write a quick utility today - just passing a few options in on the command line.  I used MSVC to create a console app and Robert was my parental sibling. However, when I ran it a MSDOS box popped up and disappeared - a bit messy. So I started a new app as a simple windows app & pasted the code in, but whoops, a windows app doesn’t start from main(argv, argc) it starts from

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)

So I spent half the day writing a parser to convert a command line into argv argc - easy enough until you allow for “this is just one param because it’s in quotes” etc.

I finally switched to unicode just so that I could use

    argv = CommandLineToArgvW(GetCommandLineW(), &argc);

but why isn’t there an ascii version? The argv / argc convention has been in use since the dawn of C, it is intrinsic to most C programs, not having it is a right pain.  Yes, I know the project was C++ not C but that is only because good old MSVC doesn’t even have a C project type.

Whilst I hate re-inventing the wheel and coding what has been coded a thousand times before I guess in these hard economic times it’s good to know there will always be work even if in a perfect world it would be pointless.

12345
Not yet rated
Loading ... Loading ...

Previous Post | Next Post

 
 
Comments
This article has no comments yet.

Make a comment

* required

* required

We stop spam using reCaptcha.
Type the words below and click Submit Comment.

Advertisement