From: Vincent Fatica on
On Mon, 07 Sep 2009 09:26:25 +0200, Ulrich Eckhardt <eckhardt(a)satorlaser.com>
wrote:

|How about this:
|
| char simem[sizeof (STARTUPINFO)] = {0};
| STARTUPINFO si = (STARTUPINFO*)simem;

Did you mean

char simem[sizeof (STARTUPINFO)] = {0};
STARTUPINFO *psi = (STARTUPINFO*)simem;

That invokes memset, gives the LNK4210 warning, makes a .CRT section, and
increases the .text segment from 0x9F bytes to 0x9AA bytes (159 to 2474).

SecureZeroMemory and __stosb avoid memset. So does

STARTUPINFO si = {sizeof(si),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

but that costs about 64 bytes later, moving 0 into each member.
--
- Vince
From: Vincent Fatica on
On Mon, 7 Sep 2009 13:56:46 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:

|"Vincent Fatica" <vince(a)blackholespam.net> wrote:
|> while ( *pCmdLine && *pCmdLine != L' ' )
|> pCmdLine += 1;
|> pCmdLine += 1;
|
|The above codes work when there's only one space between argv[0] and argv[1].
|If there's more than one space or tab, the above codes should change to:
| while ( *pCmdLine && *pCmdLine <= L' ' )
| pCmdLine += 1;

Thanks for pointing that out!

Whenever I want to get a pointer to the tail (essentially from argv[1] on) of a
command line I find myself writing some kludgy little routine like the one
above. Is there an easier/canned/customary way (with/without the RTL)?
--
- Vince
From: xiaosi on
For avoiding crt, I once wrote my_get_command_line, which is borrowed from crt source codes (__tmainCRTStartup in
VC\crt\src\crtexe.c):

LPWSTR __stdcall my_get_command_line() {
LPWSTR p = GetCommandLine();
BOOL inDoubleQuote = 0;
while (*p > L' ' || (*p && inDoubleQuote)) {
if (*p == L'\"')
inDoubleQuote = !inDoubleQuote;
p++;
}
while (*p && (*p <= L' ')) {
p++;
}
return p;
}

This is not more concise than your codes.

"Vincent Fatica" <vince(a)blackholespam.net> wrote:
> On Mon, 7 Sep 2009 13:56:46 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:
>
> |"Vincent Fatica" <vince(a)blackholespam.net> wrote:
> |> while ( *pCmdLine && *pCmdLine != L' ' )
> |> pCmdLine += 1;
> |> pCmdLine += 1;
> |
> |The above codes work when there's only one space between argv[0] and argv[1].
> |If there's more than one space or tab, the above codes should change to:
> | while ( *pCmdLine && *pCmdLine <= L' ' )
> | pCmdLine += 1;
>
> Thanks for pointing that out!
>
> Whenever I want to get a pointer to the tail (essentially from argv[1] on) of a
> command line I find myself writing some kludgy little routine like the one
> above. Is there an easier/canned/customary way (with/without the RTL)?
> --
> - Vince

From: Vincent Fatica on
On Mon, 7 Sep 2009 23:14:15 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:

|For avoiding crt, I once wrote my_get_command_line, which is borrowed from crt source codes (__tmainCRTStartup in
|VC\crt\src\crtexe.c):

Thanks for that. After grep-ing through an archive of projects for "BOOL
bInQuotes" I'm embarrassed to admit how many times I have done something
similar. :-)

Have you got any other tips on avoiding the RTL?

wsprintf() is invaluable as are the lstr* functions (now I've learned that some
of the wcs* functions have intrinsic/inline versions).

I have often wanted something to turn a string into a number. If I insist on
avoiding the RTL, I use StrToIntEx and feel a bit guilty dragging in shlwapi.dll
for only that reason.
--
- Vince
From: Alex Blekhman on
"Vincent Fatica" wrote:
> Mine is an utterly simple program (below). Without going out of
> my way at all, I apparently get the intrinsic wcslen() (no
> library, no warming, no .CRT section). memset() is another
> story!
>
> #include <windows.h>
> #include <intrin.h>
>
> INT MyWinMain(VOID)
> {
> [...]

Even if you use a custom entry point it is still must conform to
the expected signature of [w]WinMain or [w]main. Also, calling
convention must be __stdcall for Windows subsystem and __cdecl for
console subsystem.

Alex