【发布时间】:2013-10-29 12:56:32
【问题描述】:
我有这些包括:
#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*&)’候选者没有匹配的函数是:virtual HRESULT IShellLinkA::SetPath(const CHAR*)”
setDescription 出现同样的错误,显然它们被编程为虚拟,这意味着它们中没有真正的代码:
virtual HRESULT WINAPI SetPath(LPCSTR pszFile) = 0;
我一定是缺少头文件或其他东西,但我不知道。我有点迷茫,我认为不应该得到这些错误。有任何想法吗? 非常感谢你:-)
【问题讨论】:
标签: c++ compilation shortcut