arm-wince-pe: argc/argv in startup

Kai Ruottu
Tue Dec 31 05:10:00 GMT 2002

Craig Vanderborgh <> wrote:

> I have been able to get a binutils-2.11.90/gcc-3.2 toolchain going.
> I am now interested in making argc/argv available in "main()" so
> that I can create executables w/gcc that accept command-line args.
> Unfortunately it is not at all clear how to do this w/wince 3.0.

 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):

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()':

        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()'
        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

00000000 t .text
00000000 T PathFindFileName
00000000 I __imp_PathFindFileName

00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 t .text
00000000 T PathGetArgs
00000000 I __imp_PathGetArgs

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,

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

More information about the crossgcc mailing list