0

使用链接上提供的代码:http: //msdn.microsoft.com/en-us/library/aa969393.aspx

HRESULT CreateLink(LPCWSTR lpszPathObj1, 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(lpszPathObj1); 
        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; 
}

我正在尝试在桌面上创建一个快捷方式,其目标(exe)采用命令行参数。我尝试通过以下方式设置目标:

LPCWSTR lpszPathObj1 = L"C:/Folder1/Folder2/SomeApp.exe 690080776072629&734078";

使用 Target 创建快捷方式:

"C:/Folder1/Folder2/SomeApp.exe 690080666072629&782078"

LPCWSTR lpszPathObj1 = L"C:/Folder1/Folder2/SomeApp.exe\" 690080776072629&734078";

使用空白目标创建快捷方式。

我尝试了更多选择,但没有工作。有人可以帮忙吗?

4

1 回答 1

2

我假设您提到的字符串已传递给 psl->setPath()。它只是传递将由链接调用的可执行文件,您不应该将参数放在同一个字符串中。相反,在此之后调用 psl->setArguments() ,只需使用参数。字符串中的双引号没有任何区别,只有当您有其中一个带有空格的参数时才需要它们。

于 2012-05-02T16:06:17.273 回答