I’m really posting cause I’ve had this question in the past and found it slightly hard to find an answer. Eventually I did stumble upon something but it wasn’t the cleanest thing. I’ve eventually progressed in my coding knowledge and I was able to make a function that seems pretty clean. Posting here to share and hopefully it helps others.
Source: Windows Questions C++