Com 如何使用IShellLink::SetPath函数传递参数
我正在使用这个基于win32的C程序从Com 如何使用IShellLink::SetPath函数传递参数,com,win32com,Com,Win32com,我正在使用这个基于win32的C程序从 [“C:\Program Files\YP\YPseries\Bin\myexe.exe”]到 [“C:\Program Files\YP\YPseries\Bin\myexe.exe”-启动UDCDevicePage] 不包括方括号 但是当我使用 WCHAR newTargetPath[]=L“\”C:\Program Files\YP\YP series\Bin\myexe.exe\”-启动UDCDevicePage” 在main中,SetPath返回
[“C:\Program Files\YP\YPseries\Bin\myexe.exe”]到
[“C:\Program Files\YP\YPseries\Bin\myexe.exe”-启动UDCDevicePage]
不包括方括号 但是当我使用
WCHAR newTargetPath[]=L“\”C:\Program Files\YP\YP series\Bin\myexe.exe\”-启动UDCDevicePage”
在main中,SetPath返回一个E_INVALIDARG错误代码 如何使用IShellLink::SetPath函数将参数传递给myexe 程序如下所示:
HRESULT changeLinkTarget(LPCSTR pathLink, LPWSTR newTargetPath)
{
HRESULT hres;
IShellLink* psl;
WCHAR szGotPath[MAX_PATH];
WIN32_FIND_DATA wfd;
// 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, pathLink, -1, wsz, MAX_PATH);
// Load the shortcut.
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres))
{
// Get the path to the link target.
hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH);
if (SUCCEEDED(hres))
{
hres = psl->SetPath(newTargetPath);
hres = ppf->Save(wsz, TRUE); //save changes
}
else
{
// Handle the error
}
}
// Release the pointer to the IPersistFile interface.
ppf->Release();
}
// Release the pointer to the IShellLink interface.
psl->Release();
}
return hres;
}
int _tmain(int argc, _TCHAR* argv[])
{
char linkPath[128] = "C:\\Users\\Public\\Desktop\\YP series.lnk";
WCHAR newTargetPath[] = L"\"C:\\Program Files\\YP\\YP series\\Bin\\myexe.exe\" -Start UDCDevicePage";
CoInitialize(NULL); // initialize the COM subsystem
HRESULT ret = changeLinkTarget(linkPath, newTargetPath);
return 0;
}
路径通常只是一个exe;您似乎试图使用一些命令行参数将路径设置为可执行文件。请尝试使用SetPath仅对exe执行命令,而不使用额外的引号,并将其用于命令行参数。SetPath可能正试图通过检查是否存在具有您传递的完整字符串名称的exe来验证该参数,这可能是失败导致错误的原因