2012-05-02 163 views
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"; 

創建快捷方式與目標:

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

而且

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

創建空白目標快捷方式。

我試過更多的選擇,但沒有工作。有人可以幫忙嗎?

+2

你試過了什麼?我不認爲分配給'LPCWSTR'會創建一個快捷方式(即顯示您使用的代碼) –

+0

我使用的代碼來自鏈接:http://msdn.microsoft.com/en-us/ library/aa969393.aspx – eeerahul

+1

@eeerahul - 該頁面上有多個樣本,其中沒有一個具有名爲'lpszPathObj1'的變量。請顯示您*使用的代碼。 –

回答

2

我假設你提到的字符串被傳遞給psl-> setPath()。只是傳遞將由鏈接調用的可執行文件,不應將參數放在同一個字符串中。相反,在那之後調用psl-> setArguments(),只是使用參數。 字符串內部的雙引號沒有區別,只有在其中有空格的參數之一時才需要它們。