-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates #12 by reading information from the bookmark links
- Loading branch information
1 parent
b4a8b39
commit 0f7bb77
Showing
4 changed files
with
193 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* These functions based on the code found at: http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891(v=vs.85).aspx#Shellink_Resolving_Shortcut | ||
*/ | ||
|
||
// CreateLink - Uses the Shell's IShellLink and IPersistFile interfaces | ||
// to create and store a shortcut to the specified object. | ||
// | ||
// Returns the result of calling the member functions of the interfaces. | ||
// | ||
// Parameters: | ||
// lpszPathObj - Address of a buffer that contains the path of the object, | ||
// including the file name. | ||
// lpszPathLink - Address of a buffer that contains the path where the | ||
// Shell link is to be stored, including the file name. | ||
// lpszDesc - Address of a buffer that contains a description of the | ||
// Shell link, stored in the Comment field of the link | ||
// properties. | ||
|
||
#if 0 | ||
#include "stdafx.h" | ||
#endif | ||
#include "shlobj.h" | ||
#include "windows.h" | ||
#include "winnls.h" | ||
#include "shobjidl.h" | ||
#include "objbase.h" | ||
#include "objidl.h" | ||
#include "shlguid.h" | ||
|
||
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc) | ||
{ | ||
HRESULT hres; | ||
IShellLink* psl; | ||
|
||
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize | ||
// has already been called. | ||
hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl); | ||
if (SUCCEEDED(hres)) | ||
{ | ||
IPersistFile* ppf; | ||
|
||
// Set the path to the shortcut target and add the description. | ||
psl->lpVtbl->SetPath(psl,lpszPathObj); | ||
psl->lpVtbl->SetDescription(psl,lpszDesc); | ||
|
||
// Query IShellLink for the IPersistFile interface, used for saving the | ||
// shortcut in persistent storage. | ||
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
WCHAR wsz[MAX_PATH]; | ||
|
||
// Ensure that the string is Unicode. | ||
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); | ||
|
||
// Add code here to check return value from MultiByteWideChar | ||
// for success. | ||
|
||
// Save the link by calling IPersistFile::Save. | ||
hres = ppf->lpVtbl->Save(ppf,wsz, TRUE); | ||
ppf->lpVtbl->Release(ppf); | ||
} | ||
psl->lpVtbl->Release(psl); | ||
} | ||
return hres; | ||
} | ||
|
||
// ResolveIt - Uses the Shell's IShellLink and IPersistFile interfaces | ||
// to retrieve the path and description from an existing shortcut. | ||
// | ||
// Returns the result of calling the member functions of the interfaces. | ||
// | ||
// Parameters: | ||
// hwnd - A handle to the parent window. The Shell uses this window to | ||
// display a dialog box if it needs to prompt the user for more | ||
// information while resolving the link. | ||
// lpszLinkFile - Address of a buffer that contains the path of the link, | ||
// including the file name. | ||
// lpszPath - Address of a buffer that receives the path of the link | ||
// target, including the file name. | ||
// lpszDesc - Address of a buffer that receives the description of the | ||
// Shell link, stored in the Comment field of the link | ||
// properties. | ||
|
||
HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath, int iPathBufferSize) | ||
{ | ||
HRESULT hres; | ||
IShellLink* psl; | ||
CHAR szGotPath[MAX_PATH]; | ||
CHAR szDescription[MAX_PATH]; | ||
WIN32_FIND_DATA wfd; | ||
|
||
*lpszPath = 0; // Assume failure | ||
|
||
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize | ||
// has already been called. | ||
hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl); | ||
if (SUCCEEDED(hres)) | ||
{ | ||
IPersistFile* ppf; | ||
|
||
// Get a pointer to the IPersistFile interface. | ||
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (void**)&ppf); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
WCHAR wsz[MAX_PATH]; | ||
|
||
// Ensure that the string is Unicode. | ||
MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); | ||
|
||
// Add code here to check return value from MultiByteWideChar | ||
// for success. | ||
|
||
// Load the shortcut. | ||
hres = ppf->lpVtbl->Load(ppf,wsz, STGM_READ); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
// Resolve the link. | ||
hres = psl->lpVtbl->Resolve(psl,hwnd, 0); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
// Get the path to the link target. | ||
hres = psl->lpVtbl->GetPath(psl,szGotPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
// Get the description of the target. | ||
hres = psl->lpVtbl->GetDescription(psl,szDescription, MAX_PATH); | ||
|
||
if (SUCCEEDED(hres)) | ||
{ | ||
/* TODO: Check success */ | ||
strncpy(lpszPath, szGotPath, iPathBufferSize); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Release the pointer to the IPersistFile interface. | ||
ppf->lpVtbl->Release(ppf); | ||
} | ||
|
||
// Release the pointer to the IShellLink interface. | ||
psl->lpVtbl->Release(psl); | ||
} | ||
return hres; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#if !defined SHRTCUT_H | ||
#define SHRTCUT_H | ||
|
||
extern HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath, int iPathBufferSize); | ||
|
||
#endif |