This is a mirror of official site: http://jasper-net.blogspot.com/

How is the CommandLineToArgvW function intended to be used ?

| Tuesday, September 21, 2010
The CommandLineToArgvW function does some basic command line parsing. A customer reported that it was producing strange results when you passed an empty string as the first parameter:

LPWSTR argv = CommandLineToArgvW(L"", &argc);
Well, okay, yeah, but huh?

The first parameter to CommandLineToArgvW is supposed to be the value returned by GetCommandLineW. That's the command line, and that's what CommandLineToArgvW was designed to parse. If you pass something else, then CommandLineToArgvW will try to cope, but it's not really doing what it was designed for.

It turns out that the customer was mistakenly passing the lpCmdLine parameter that was passed to the wWinMain function:

int WINAPI wWinMain(
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPWSTR lpCmdLine,
   int nCmdShow)
{
   int argc;
   LPWSTR argv = CommandLineToArgvW(lpCmdLine, &argc);
   ...
}

Read more: The old new thing

Posted via email from .NET Info

0 comments: