I use the following code to resolve a shortcut, but the CoUninitialize gives an access violation. What's wrong?
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'; // Assume failure
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
// Get a pointer to the IPersistFile interface.
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
// Load the shortcut.
hres = ppf->Load(LinkFile, STGM_READ);
hres = psl->Resolve(GetDesktopWindow(), 0);
// Get the path to the link target.
hres = psl->GetPath(Path, MAX_PATH, 0, SLGP_SHORTPATH);
// Release the pointer to the IPersistFile interface.
// Release the pointer to the IShellLink interface.
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.