#define _CRT_SECURE_NO_WARNINGS // 'wcstombs' の警告を無効化 #define _WIN32_WINNT 0x0600 // またはそれ以上のバージョン #include #include #include #pragma comment(lib, "Shell32.lib") // 必要なライブラリをリンク int main() { char desktopPath[MAX_PATH]; if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath))) { printf("Desktop Path: %s\n", desktopPath); } char favoritesPath[MAX_PATH]; if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL, 0, favoritesPath))) { printf("Favorites Path: %s\n", favoritesPath); } char myDocumentsPath[MAX_PATH]; if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, myDocumentsPath))) { printf("My Documents Path: %s\n", myDocumentsPath); } // システムフォルダへのパスの取得 char systemFolderPath[MAX_PATH]; if (GetSystemDirectoryA(systemFolderPath, MAX_PATH)) { printf("System Folder Path: %s\n", systemFolderPath); } // Start Menu Pathの取得 PWSTR startMenuPath; if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_StartMenu, 0, NULL, &startMenuPath))) { char startMenuPathStr[MAX_PATH]; size_t convertedChars = 0; wcstombs_s(&convertedChars, startMenuPathStr, MAX_PATH, startMenuPath, MAX_PATH); // ワイド文字列をマルチバイト文字列に安全に変換 printf("Start Menu Path: %s\n", startMenuPathStr); CoTaskMemFree(startMenuPath); // メモリリークを防ぐために解放する } return 0; }