Article View: borland.public.cppbuilder.nativeapi
Article #10863Re: Command Line Arguments
From: Remy Lebeau (TeamB)
Date: Thu, 11 Mar 2004 20:58
Date: Thu, 11 Mar 2004 20:58
41 lines
2267 bytes
2267 bytes
"p Anders" <paul.anderson@jhuapl.edu> wrote in message
news:4050cd3f$1@newsgroups.borland.com...
> what in the world is this return type "LPWSTR"
> and what is this parameter "LPCWSSTR"?
LPWSTR = wchar_t*
LPCWSTR = const wchar_t*
You can see the actual declarations for yourself in wtypes.h
> Can anyone tell me how in the world I use this to convert
> the result of the GetCommandLine argument into a standard
> char* argv[]?
Use GetCommandLineW() (notice the W) to get the command line as a Unicode
string (or use GetCommandLineA() and then call MultiByteToWideChar()), and
then pass the string to CommandLineToArgvW(). It will return an allocated
array of Unicode strings and the number of entries in the array. You can
then loop through the array converting the Unicode strings to ANSI strings
as needed. For example:
int my_argc = 0;
LPWSTR* my_argv = CommandLineToArgvW(GetCommandLineW(), &my_argc);
if( NULL != my_argv )
{
for(int i = 0; i < my_argc; ++i)
// use my_argv[i] as needed...
GlobalFree(my_argv);
}
BTW, CommandLineToArgvW() is not available on Win9x/ME at all. If you need
a solution that works across OS versions, then you will just have to parse
the command line manually, or use the VCL's ParamCount() and ParamStr()
functions.
Gambit
Technical Details
Message-ID:
<4050d0dd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4050cd3f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,883b2e2ca964e949 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-11 13:10:40 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4050cd3f$1@newsgroups.borland.com> Subject: Re: Command Line Arguments Date: Thu, 11 Mar 2004 12:58:29 -0800 Lines: 43 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <4050d0dd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079038173 67.22.138.253 (11 Mar 2004 12:49:33 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail