View Single Post
  #2  
Old 06-07-2024, 18:05
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 431
Rept. Given: 26
Rept. Rcvd 130 Times in 67 Posts
Thanks Given: 54
Thanks Rcvd at 837 Times in 306 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
You can also do something similar to this by using the built-in 'std::shared_ptr' type. It allows for initialization with a custom deleter function. With that, you can pass a type cleanup call for types that have one. (You can also just define your own callback to cleanup custom/more unique types as needed.)

For example, using a 'HANDLE' type, which is cleaned up using 'CloseHandle':

PHP Code:
const std::shared_ptr<voidhandle(::OpenProcess(PROCESS_VM_READFALSEpid), ::CloseHandle); 
Usage is then similar to your setup by just using 'handle.get()' to obtain the actual handle.
__________________
Personal Projects Site: https://atom0s.com

Last edited by atom0s; 06-08-2024 at 04:49. Reason: Forum breaks C++ code using the normal code tags; changed to php tags instead.
Reply With Quote
The Following 3 Users Say Thank You to atom0s For This Useful Post:
MarcElBichon (06-07-2024), SofTw0rm (06-11-2024), tonyweb (06-08-2024)