News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Link /ENTRY and windows entry points main WinMain

Started by TouEnMasm, August 06, 2020, 11:26:05 PM

Previous topic - Next topic

TouEnMasm

Hello,
I have searched a while why old VC console programs  doesn't work now.
The reason is a change in the number of arguments .
Old:
main PROTO C argc:DWORD ,argv:XMASM      (XMASM= DWORD in 32,Qword in 64)
New:
Quote
;-----main( int argc, char *argv[ ], char *envp[ ] );-------------------
main PROTO C argc:DWORD ,argv:XMASM ,envp:XMASM
the WinMain don't seem to have changed.
Quote
;int  WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR     lpCmdLine, int nShowCmd);
WinMain PROTO hInstance:HINSTANCE ,hPrevInstance:HINSTANCE ,lpCmdLine:XMASM ,nShowCmd:DWORD
With WinMain there is to take care than some headers describe it with  __clrcall
To be an Entry Point only the stdcall work (msdn)

Using this two defines with the ucrt.lib and the msvcrt.lib give a complete integration with the crt.
The  lpCmdLine return a pointer on the command line ,argc return the number of argument.
main,wmain(UNICODE) works with the Link /SUBSYSTEM:CONSOLE.
WinMain,wWinMain(UNICODE) works with the link /SUBSYSTEM:WINDOWS

Quote
The two are recognized by the crt as entry point and there is no need of link /ENTRY

The exitprocess is optionnal,he is done after the end of the prog in the (W)maincrtstartup.
Tested in 32 bits,perhaps is there little modifies in 64
Fa is a musical note to play with CL

Vortex

Hi TouEnMasm,

I would recommend you to write your own C run-time startup modules. They don't need to be complicated like the ones provided by M$ trying always to complicate things.