我有這些包括:錯誤試圖創建快捷方式[C++]
#include <stdafx.h>
#include <winnls.h>
#include <shobjidl.h>
#include <shlobj.h>
#include <shlguid.h>
#include <objbase.h>
#include <objidl.h>
#include <windows.h>
,我發現這個代碼,以使快捷鍵:
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCSTR lpszPathLink, LPCWSTR 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->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(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->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
但我發現了這些編譯錯誤: 「沒有匹配的函數調用'IShellLinkA :: SetPath(const WCHAR * &)'候選人是:虛擬HRESULT IShellLinkA :: SetPath(const CHAR *)「
我得到相同的錯誤或setDescription,顯然他們被編程爲虛擬的,這意味着在他們沒有真正的代碼:
virtual HRESULT WINAPI SetPath(LPCSTR pszFile) = 0;
我必須失去一個頭文件或東西,但我不知道。我有點失落,我認爲不應該得到這些錯誤。有任何想法嗎? Thankyou非常:-)