讀取捷徑檔內的資訊 |
尚未結案
|
Outbreak
一般會員 發表:1 回覆:2 積分:0 註冊:2002-08-25 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
ericosur
一般會員 發表:0 回覆:15 積分:8 註冊:2002-08-08 發送簡訊給我 |
這一段從 MSDN 抄出來的,試試看吧
原則上是利用 IShellLink 這個 COM Interface 來幫我們完成這個動作
看不種的話需要閱讀 COM 的相關資料,使用 COM 元件算是 COM 程式
設計的基本技巧 //
// from MSDN - Shell Links - Resolving a Shortcut
// HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
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.
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->QueryInterface(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); // Load the shortcut.
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres)) { // Resolve the link.
hres = psl->Resolve(hwnd, 0);
if (SUCCEEDED(hres)) { // Get the path to the link target.
hres = psl->GetPath(szGotPath,
MAX_PATH, (WIN32_FIND_DATA *)&wfd,
SLGP_SHORTPATH );
if (FAILED(hres))
HandleErr(hres); // application-defined function // Get the description of the target.
hres = psl->GetDescription(szDescription, MAX_PATH);
if (FAILED(hres))
HandleErr(hres);
lstrcpy(lpszPath, szGotPath);
}
}
// Release the pointer to the IPersistFile interface.
ppf->Release();
}
// Release the pointer to the IShellLink interface.
psl->Release();
}
return hres;
}
|
anpino
版主 發表:31 回覆:477 積分:231 註冊:2003-01-02 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |