Archived

This topic is now archived and is closed to further replies.

Sfpiano

IPersistFile->Load()

Recommended Posts

IShellLink* dsktopLnk;
	char pszLoc[MAX_PATH];
	WIN32_FIND_DATA pfd;
	HRESULT hResult;
	hWnd = ::GetDesktopWindow();

	CoInitialize(NULL);

	// Get a pointer to the IShellLink interface. 
    hResult = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, 
                            IID_IShellLink, (LPVOID*)&dsktopLnk);

	if(SUCCEEDED(hResult)){
		IPersistFile* ipf;
		// Get a pointer to the IPersistFile interface. 
        hResult = dsktopLnk->QueryInterface(IID_IPersistFile, (void**)&ipf); 

		if(SUCCEEDED(hResult)){

			WCHAR wsz[MAX_PATH]; 
			char lpszLinkFile[MAX_PATH];
			lstrcpy(lpszLinkFile, "C:\\Documents and Settings\\All Users\\Desktop");
            // Ensure that the string is Unicode. 
            MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); 
            // Load the shortcut. 
///////HERE///////////
            hResult = ipf->Load(wsz, STGM_WRITE);
///////END HERE///////
			if(SUCCEEDED(hResult)){
				hResult = dsktopLnk->Resolve(hWnd, 0);
				if(SUCCEEDED(hResult)){
					dsktopLnk->GetPath(pszLoc, MAX_PATH, (WIN32_FIND_DATA*)&pfd, NULL);

					MessageBox(NULL, pszLoc, "SDFL", NULL);
				}
			}
		}
		ipf->Release();
	}
	dsktopLnk->Release();	
	CoUninitialize();
 
Everything works fine until the Load() call. The really odd thing is is doesn''t return S_OK, E_FAIL, or E_OUTOFMEMORY, it returns -2147024891. //------------------------------------------------------------------------------------------------------ The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you''re the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."

Share this post


Link to post
Share on other sites