I use the following code to resolve a shortcut, but the CoUninitialize gives an access violation. What's wrong?
WCHAR FullName[MAX_PATH];
HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);
HRESULT hr = ResolveIt(fname, FullName, MAX_PATH);
CoUninitialize(); // This still gives access violation
HRESULT ResolveIt(WCHAR *LinkFile, WCHAR Path[], int iPathBufferSize)
{
Path[0] = '\0';
IShellLink* psl;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres))
{
hres = ppf->Load(LinkFile, STGM_READ);
hres = psl->Resolve(GetDesktopWindow(), 0);
if (SUCCEEDED(hres))
{
hres = psl->GetPath(Path, MAX_PATH, 0, SLGP_SHORTPATH);
}
ppf->Release();
}
psl->Release();
}
return hres;
}
What I have tried:
I tried doing without the ->Resolve interface call and changing parameters, but the access violation stays. My sample uses UNICODE, so character to wide character conversion should not be necessary. The returned path is correct and all returned HRESULT values are S_OK.