View Full Version : Thank you for PointerToWString

Allan Greis Eriksen
2-Nov-2022, 11:32 AM
I just want to say thanks for this awesome function
PointerToWString() Using this with indirect conversion to the native utf-8 string works really well. Working with windows API calls where the length of the utf-16 string is unknown but zero terminated and referenced with a pointer would be a greater challenge without this function.
Here is an example code where I am parsing a list of WTS_SESSION_INFOW structures as a result from an external function WTSEnumerateSessionsW api call.

For iCountSessionInfo from 0 to (dwCount - 1)
Move (DeRefDw(lpSessionRow, 0)) to lsaSessionInfo[iCountSessionInfo].iSessionID
Move (DeRefDw(lpSessionRow, 4)) to lpName
Move (PointerToWString(lpName)) to lsaSessionInfo[iCountSessionInfo].sStationName
Move (DeRefDw(lpSessionRow, 8)) to lsaSessionInfo[iCountSessionInfo].iState
Move (lpSessionRow + 12) to lpSessionRow

Note the highlighted code. I have no knowledge of how log the UTF-16 encoded station name is but I know it is zero terminated. But I cannot use CStringSize() as it is UTF-16. But the function used returns a WString type value from the address (pointer type) and then does an indirect conversion to the native UTF-8 string in the struct. A lot behind the scenes but still simple. Love it!

Dennis Piccioni
2-Nov-2022, 03:10 PM
Fantastic! :)