News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ending a ucrt entry point program

Started by TouEnMasm, June 24, 2020, 07:16:09 PM

Previous topic - Next topic

TouEnMasm

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

What happens if you put an int 3 before your invoke ExitProcess, 0? Does it hang somewhere?

hutch--

Yves, it sounds like it does not shut down properly. Exit the app with ExitProcess().

TouEnMasm

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


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

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

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:

daydreamer

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
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding