arm-wince-pe: argc/argv in startup

Craig Vanderborgh
Tue Dec 31 08:23:00 GMT 2002

Hello Kai, and Happy New Year to all..

I dug up an answer to the argc/argv thing I think will work, and I thought
crossgcc might like to hear about it.
First, it is true that something similar to a shell is needed to get
argc/argv into a Wince 3.0 process.  Right now, we're doing this with
the RAPI function CECreateProcess, which allows you to pass command
line args.

We do have our own gcc-specific startup stuff that replaces "corelibc".
This part of the system does a few things in assembly language, then
calls our own _startup(), which is C, which in turn calls main().
Micro$oft's coredll.dll provides something called "GetCommandLine()",
which gets the commandline args for the current process as a wide string.
So we're going to create argc/argv in our _startup(), populate it from the
parsed commandline string, and then pass argc/argv to main.  I haven't done
this yet but it's fairly clear that it will work.
craig vanderborgh
voxware incorporated

Kai Ruottu wrote:
>  Is there a 'console' available in WinCE 3.0 ?  AFAIK using
> 'main()' is related to console apps while 'WinMain()' is related
> to GUI apps.
> > I tried to use the mingw sources as a guide, but M$ provides a
> > function called (__getmainargs) on Windows 95/98/2k... that is
> > not available on wince.  Dumping out the contents of "corelibc.lib"
> > hasn't been particularly instructive either.
>  The 'corelibc.lib' seems to be one alternative for the 'runtime'
> C-library meanwhile there is also the 'msvcrt.lib' import library
> for the 'msvcrt.dll', at least in those WinCE 2.0 libraries I have
> (for MIPS and SH). Unfortunately neither this seemed to have anything
> related to getting the main 'args' in its 'crtexe.obj' (MIPS-one):
> crtw32/dllstuff/obj_mips_h/crtexe.obj:
> 00000000 p .pdata
> 00000000 t .text
>          U WinMain
> 00000000 T WinMainCRTStartup
> 00000004 C __defaultmatherr
>          U __imp_exit
>          U __setusermatherr
>          U _cinit
>          U _matherr
> I didn't try to disassemble this (with 'objdump -dr'), but looked
> at the 'pegwmain.o' in 'corelibc.lib' and it simply called the
> '_cinit()', then 'WinMain()' and finally 'exit()':
> WinMainCRTStartup:
>         addiu   $sp,$sp,-24     ; set the stack frame
>         sw      $ra,20($sp)     ; push important ? stuff there
>         sw      $a0,24($sp)
>         sw      $a1,28($sp)
>         sw      $a2,32($sp)
>         sw      $a3,36($sp)
>         jal     _cinit          ; call '_cinit()'
>         nop
>         lw      $a0,24($sp)     ; restore a0...a2
>         lw      $a1,28($sp)
>         lw      $a2,32($sp)
>         jal     WinMain         ; call 'WinMain()'
>         lw      $a3,36($sp)     ; restore a3
>         jal     exit            ; call 'exit()'
>         move    $a0,$v0
>         lw      $ra,20($sp)
>         jr      $ra
>         addiu   $sp,$sp,24
>  And the '_cinit()' called here didn't seem to get the args from
> anywhere... The 'msvcrt.lib' equivalent seems to add 'matherr'
> here but nothing else.
>  Looking at the docs for the 'CreateProcess()' could tell something,
> whether any args, environ etc. will be given to the new process and
> where they are when the 'WinMainCRTStartup()' is called. In the
> MIPS-case there are some info in the CPU regs when starting the
> executable at 'WinMainCRTStartup()'. My WinCE-docs didn't tell
> anything about the parameters for 'WinMainCRTStartup()'...
>  A 'shell' ie 'command interpreter' is normally related to 'console',
> and when there was that 'ceshell.lib', I looked at it too. There
> seemed to be something with 'GetArgs', but again no info in the WinCE
> docs:
> 00000000 t .text
> 00000000 T PathFindFileName
>          U __IMPORT_DESCRIPTOR_CEShell
> 00000000 I __imp_PathFindFileName
> CEShell.DLL:
> 00000000 i .idata$4
> 00000000 i .idata$5
> 00000000 i .idata$6
> 00000000 t .text
> 00000000 T PathGetArgs
>          U __IMPORT_DESCRIPTOR_CEShell
> 00000000 I __imp_PathGetArgs
> CEShell.DLL:
> 00000000 i .idata$4
> 00000000 i .idata$5
> 00000000 i .idata$6
> 00000000 t .text
> 00000000 T PathIsDirectory
>  No functions starting with 'Path' was documented... Probably
> these parse args from a command line.
>  With SVR4 the stuff given to '_start()' (the process entry name
> there) has been documented at least somehow and maybe the Win32
> PlatformSDK-docs or the newer WinCE 3.0 SDK docs tell more about
> the process entry at 'WinMainCRTStartup()'. Finding all the info
> related to this is your best bet...
>  My stupid questions coming from the previous:
>  Ok, when there seems to be two C-libraries, the 'corelibc.lib'
> for 'statically' linked executables and the 'msvcrt.lib' for
> 'dynamically' linked executables using 'msvcrt.dll' at runtime,
> have you tried them both ?
>  With MinGW there are the older 'crtdll.dll' and the newer
> 'msvcrt.dll' as the runtime alternatives with their related
> import libs at link time, and not so many use the older one
> at all nowadays...
>  Which one is the preferred one with WinCE 3.0, the 'corelibc.lib'
> or the 'msvcrt.lib' as the link-time C-library ?
>  Happy New Year,
>  Kai

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

More information about the crossgcc mailing list