2012-05-02 5 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()を呼び出してください。 文字列内の二重引用符は違いはありませんが、その中に空白を含む引数の1つがある場合にのみ必要になります。

関連する問題