Author Topic: ending a ucrt entry point program  (Read 187 times)

TouEnMasm

  • Member
  • *****
  • Posts: 1289
    • EditMasm
ending a ucrt entry point program
« on: June 24, 2020, 07:16:09 PM »
I have an application using the ucrt
I have made it ended in the same way as with the use of the msvcrt.
The end of the progam seem complete,but...
When I try to delet this application,I can't,he is recognize as already in use ??????
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 10446
  • Assembler is fun ;-)
    • MasmBasic
Re: ending a ucrt entry point program
« Reply #1 on: June 24, 2020, 08:58:34 PM »
What happens if you put an int 3 before your invoke ExitProcess, 0? Does it hang somewhere?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7447
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: ending a ucrt entry point program
« Reply #2 on: June 24, 2020, 09:41:56 PM »
Yves, it sounds like it does not shut down properly. Exit the app with ExitProcess().
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TouEnMasm

  • Member
  • *****
  • Posts: 1289
    • EditMasm
Re: ending a ucrt entry point program
« Reply #3 on: June 24, 2020, 10:35:53 PM »
As usual,there is no use of exitprocess in all crt entry point
Link as the option /entry:wWinMain
Quote
wWinMain proc hInst:DWORD,hPrevInst:DWORD,lpCmdLine:DWORD,nShowCmd:DWORD
       ..................
        -------------
   mov eax,0
   ret
;wmain endp
wWinMain endp
return value are always 0
events
Quote
.ELSEIF uMsg == WM_CLOSE ;return zero
          ..........destroy all windows,free memory ..
               mov retour,0
.ELSEIF uMsg == WM_DESTROY
          ............
      INVOKE     PostQuitMessage, NULL
      mov retour,0
.else
      mov eax,retour
      INVOKE     DefWindowProc, hwnd, uMsg, wParam, lParam      
      mov retour,eax      

endif




Fa is a musical note to play with CL

TouEnMasm

  • Member
  • *****
  • Posts: 1289
    • EditMasm
Re: ending a ucrt entry point program
« Reply #4 on: June 24, 2020, 10:50:36 PM »

The exitprocess at the end of wWinMain solve the problem but isn't a normal practice.
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 10446
  • Assembler is fun ;-)
    • MasmBasic
Re: ending a ucrt entry point program
« Reply #5 on: June 24, 2020, 11:39:29 PM »
Code: [Select]
WinMain proc
LOCAL msg:MSG
  wc equ [ebx.WNDCLASSEX] ; we use an equate for better readability
  mov ebx, offset wcx
  mov wc.hInstance, rv(GetModuleHandle, 0) ; rv ("return value") is a Masm32 macro
  mov wc.hIcon, rv(LoadIcon, eax, IDI_APPLICATION)
  mov wc.hIconSm, eax ; the rv macro returns results in eax
  mov wc.hCursor, rv(LoadCursor, NULL, IDC_ARROW) ; get a cursor
  invoke RegisterClassEx, addr wc ; the window class needs to be registered
  invoke CreateWindowEx, WS_EX_ACCEPTFILES, wc.lpszClassName, chr$("Hello World"), ; set window title here
     WS_OVERLAPPEDWINDOW or WS_VISIBLE,
     600, 150, 600, 400, ; window position: x, y, width, height
     NULL, rv(LoadMenu, wc.hInstance, 100), wc.hInstance, NULL
  .While 1
invoke GetMessage, addr msg, 0, 0, 0
inc eax
shr eax, 1
.Break .if Zero?
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
  .Endw
  if 1
ret ; ->RtlExitUserThread
  else
invoke ExitProcess, msg.wParam ; <<<<<<<<<<<<<<<<< normal practice since roughly 1995
  endif
WinMain endp

Yves,

We could argue a lifetime what is "normal" or "correct practice" (and some do argue), but as a matter of fact you do have the two options above: ret or ExitProcess, both on exiting the message loop.

The simple ret takes you, a nanosecond later, to RtlExitUserThread, which is not better than ExitProcess. The latter never fails, but occasionally, the simple ret takes you in no man's land - in that case, check your stack, it may be corrupt.

felipe

  • Member
  • *****
  • Posts: 1323
  • Eagles are just great!
Re: ending a ucrt entry point program
« Reply #6 on: June 25, 2020, 01:48:26 AM »
ExitProcess will closes open handles and others, so if you don't call it at the end of your app and after closing it (apparently) it still runs, that maybe an indication of some form of memory leak where you have not released a resource used by your app to windows.  :icon_idea:
Felipe.

daydreamer

  • Member
  • *****
  • Posts: 1315
  • building nextdoor
Re: ending a ucrt entry point program
« Reply #7 on: June 25, 2020, 01:58:48 AM »
I usually add extra exitprocess option if I Detect KEY_DOWN is VK_ESCAPE ,but its following old fullscreen demo tradition,maybe thats "normal" exit habit for demomakers and I find that is convenient faster way than different mouseclicking exit program options in a "normal" windows program
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)