I have seen similar questions (e.g. Encode/Decode URLs in C++). But, for me:
CString strURL;
DWORD dwSize = _MAX_PATH;
if (InternetCanonicalizeUrl(strFile, strURL.GetBuffer(_MAX_PATH), &dwSize, ICU_BROWSER_MODE))
{
// still has backslash
AfxMessageBox(strURL);
}
strURL.ReleaseBuffer();
strURL = strFile;
strURL.Replace(L"\\", L"/");
strURL = L"file:///" + strURL;
AfxMessageBox(strURL);
Using InternetCanonicalizeUrl
did not work:
- The prefix was
file://
and notfile:///
. - The
\
was not replaced with/
.
I did it manually and my version of the URL works with my subsequent WebView2
function. To clarify, the path itself was built with ::GetTempPath()
and/or ::GetTempFileName()
.
Why did the built-in API call not do what I needed?