The MASM Forum

General => The Workshop => Topic started by: TouEnMasm on August 06, 2020, 11:26:05 PM

Title: Link /ENTRY and windows entry points main WinMain
Post by: TouEnMasm on August 06, 2020, 11:26:05 PM
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
Title: Re: Link /ENTRY and windows entry points main WinMain
Post by: Vortex on August 06, 2020, 11:38:37 PM
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.