Hi guys, how to safelly close an application from a dll ?
I mean, i´m making some separated libraries for usage in RosAsm.exe. One of the library is called "RosMem.dll" that is responsable for memory managment of RosAsm memory usage.
Inside RosMem.dll i want to insert a "kernel32.ExitProcess" to close the main RosAsm.exe that called that dll, but how to retrieve the exit code of the executable file ?
I mean, if i place call 'kernel32.ExitProcess' 0 from the dll it will close the caller (RosAsm.exe) too ?
Also...what happens if there are other instances of RosAsm opened at the same time that also uses this dll ?
This is because i can have more then 01 Instance of RosAsm.exe which i´m testing for a specific reason (Ex: One i may debugging a app and the other instance i may use to create a resource or load a lib file etc)...
But...let´s say that on instance 1 (The rosasm i´m using for debug) i find a bug from where i need to terminate only this process using RosMem.dll and not using kernel32.ExitProcess inside the main executable ?
I read on the forum about using KeBugCheck but i think it is not the case here, since i don´t want the system hang, i want only that the main executable safely terminate (Even if i have other instance of the executable running)
For example if i get the handle from the main dll proc (hInstance) can i use GetExitCodeProcess to close only this caller ?
Ex: mine dll starts with
[hCallerInstance: D$ 0]
Proc Main:
Arguments @Instance, @Reason, @Reserved
move D$hCallerInstance D@Instance ; Not used here...
If D@Reason = &DLL_PROCESS_ATTACH
; ...
; I first thought it was possible to call to 'RandomizeTimer' initialisation
; from here, but it is *not*. You can only do simple initialisations tasks,
; and the GetTickCount api can't be call at load time. So, the user has to
; make a call to 'RandomizeTimer' by himself, if he wants the values to be
; different at each run.
;
; There is now a simple x86 instruction that does it as well:
;;; RDTSC
; But, as the "Read Time-Stamp Counter" Instruction was introduced into
; the Intel Architecture in the Pentium processor, i perfer the
; 'RandomizeTimer' Routine available for runing on older Computers.
Else_If D@Reason = &DLL_PROCESS_DETACH
; ...
Else_If D@Reason = &DLL_THREAD_ATTACH
; ...
Else_If D@Reason = &DLL_THREAD_DETACH
; ...
End_If
mov eax &TRUE
EndP
Can i use this routine inside a export function on that dll like:
[ExitCode: D$ 0]
Proc MyFunction:: ;<---- double "::" means it is used as an export in RosAsm (On this case, the export is on a dll)
(....)
call 'kernel32.GetExitCodeProcess' D$hCallerInstance, ExitCode
call 'kernel32.ExitProcess' D$ExitCode
EndP
Is it going to close one instance of RosAsm.exe (or any other app that used RosMem.dll) and leave other instance intact (that also uses the dll) ? Or it will terminate both apps, just because they use the same dll ?