This looks way too complicated, especially what's going on in 8/8. Have you checked if some existing API in kernelbase or shell32 could be used instead? Manual path manipulations feel wrong to me. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/343#note_3284