|  ショートカットファイル(*.lnk)を作成するには
   ショートカットファイルを作成するには、IShellLink インターフェースを使用します。ショートカットファイルはフォーマットが簡単なので、バイナリで直接作成することもできなくないのですが、Windowsのバージョンが変わった際にフォーマットが異なると怖いので、IShellLink を使用しましょう。
   以下は、サンプルになります。                        
					     					      ※ ANSIコンパイル用のみですが、UNICODE版の方が簡単です。※ "C:\temp\sample.exe" のショートカットを "C:\temp\sample.lnk" として作成します。先に"C:\temp\sample.exe"に適当なEXEファイルを置いてください。
  ■■■ createshortcut プロジェクト ■ main.cpp
 
                          
                            | #include <windows.h> #include <shlobj.h>
 
 // ショートカット作成
 BOOL CreateShortcut ( const char *pszTargetPath /* ターゲットパス */,
 const char *pszArguments /* 引数 */,
 const char *pszWorkPath /* 作業ディレクトリ */,
 int nCmdShow /* ShowWindowの引数 */,
 const char *pszShortcutPath /* ショートカットファイル(*.lnk)のパス */ )
 {
 IShellLink *psl;
 IPersistFile *ppf;
 enum
 {
 MY_MAX_PATH = 65536
 };
 WCHAR wcLink[ MY_MAX_PATH ];
 
 // IShellLinkインターフェースの作成
 if ( FAILED ( CoCreateInstance ( CLSID_ShellLink, NULL,CLSCTX_INPROC_SERVER, IID_IShellLink, ( void ** ) &psl ) ) )
 {
 return FALSE;
 }
 
 // 設定
 psl->SetPath ( pszTargetPath );
 psl->SetArguments ( pszArguments );
 psl->SetWorkingDirectory ( pszWorkPath );
 psl->SetShowCmd ( nCmdShow );
 
 // IPersistFileインターフェースの作成
 if ( FAILED ( psl->QueryInterface ( IID_IPersistFile, ( void ** ) &ppf ) ) )
 {
 psl->Release ();
 return FALSE;
 }
 
 // lpszLinkをWCHAR型に変換
 MultiByteToWideChar ( CP_ACP, 0, pszShortcutPath, -1, wcLink, MY_MAX_PATH );
 if ( FAILED ( ppf->Save ( wcLink, TRUE ) ) )
 {
 ppf->Release ();
 return FALSE;
 }
 
 // 解放
 ppf->Release ();
 psl->Release ();
 
 return TRUE;
 }
 
 // エントリポイント
 int WINAPI WinMain ( HINSTANCE,
 HINSTANCE,
 char *,
 int )
 {
 // "C:\\temp\\sample.exe" のショートカットを "C:\\temp\\sample.lnk"として作成します。
 
 CreateShortcut ( "C:\\temp\\sample.exe",
 "",
 "C:\\temp",
 SW_SHOW,
 "C:\\temp\\sample.lnk" );
 
 return 0;
 }
 
 |  |