#include #include int main() { // ショートカットの対象となるファイルのパス LPCWSTR targetPath = L"C:\\Users\\SEEDAGX\\source\\repos\\Shortcut\\x64\\Debug\\Shortcut.exe"; // ショートカットの保存先ディレクトリ LPCWSTR shortcutPath = L"C:\\Users\\SEEDAGX\\source\\repos\\Shortcut\\Shortcut\\Shortcut.lnk"; // CoInitializeの呼び出し HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) { // エラー処理 return 1; } // IShellLinkとIPersistFileのインターフェースを取得 IShellLink* pShellLink = NULL; hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&pShellLink); if (FAILED(hr)) { // エラー処理 CoUninitialize(); return 1; } IPersistFile* pPersistFile = NULL; hr = pShellLink->lpVtbl->QueryInterface(pShellLink, &IID_IPersistFile, (LPVOID*)&pPersistFile); if (FAILED(hr)) { // エラー処理 pShellLink->lpVtbl->Release(pShellLink); CoUninitialize(); return 1; } // ショートカットの対象を設定 hr = pShellLink->lpVtbl->SetPath(pShellLink, targetPath); if (FAILED(hr)) { // エラー処理 pPersistFile->lpVtbl->Release(pPersistFile); pShellLink->lpVtbl->Release(pShellLink); CoUninitialize(); return 1; } // ショートカットを保存 hr = pPersistFile->lpVtbl->Save(pPersistFile, shortcutPath, TRUE); if (FAILED(hr)) { // エラー処理 pPersistFile->lpVtbl->Release(pPersistFile); pShellLink->lpVtbl->Release(pShellLink); CoUninitialize(); return 1; } // インターフェースを解放 pPersistFile->lpVtbl->Release(pPersistFile); pShellLink->lpVtbl->Release(pShellLink); // CoUninitializeの呼び出し CoUninitialize(); return 0; }