Re-inventing the wheel, argv / argc in windows
Posted in Coding, Microsoft on August 10, 2009 at 3:48 pm
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.
Make a comment
Tag cloud
Archives
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
Most commented posts
Highest Rated Blog Posts
- PC Advance Required (100%)
- No excuse - it's free to encrypt! (100%)
- Virtualization's Dark Side - or stating the obvious for beginners (100%)
- Tabs - I might change my mind? (100%)
- Which Linux do you drink? (100%)
- Sat Nag (100%)
- How to be a Guitar Hero (100%)
- Home working - a tale of freedom, loneliness and slippers (100%)
- Vertigo (100%)
- Is your back door open? (90%)

