スクリプトをC++に翻訳しました:
#include <shldisp.h>
void RenameDrive(BSTR strNewName, BSTR strDriveLetter)
{
IShellDispatch* pShellDispatch = NULL;
HRESULT hr = CoCreateInstance(CLSID_Shell,
NULL,
CLSCTX_INPROC_SERVER,
IID_IShellDispatch,
(void**)&pShellDispatch);
if (SUCCEEDED(hr) && pShellDispatch)
{
Folder* pFolder = NULL;
VARIANT vt = {};
VariantInit(&vt);
vt.vt = VT_BSTR;
vt.bstrVal = strDriveLetter;
hr = pShellDispatch->NameSpace(vt, &pFolder);
VariantClear(&vt);
if (SUCCEEDED(hr) && pFolder)
{
Folder2* pFolder2 = NULL;
hr = pFolder->QueryInterface(IID_Folder2, (void**)&pFolder2);
if (SUCCEEDED(hr) && pFolder2)
{
FolderItem* pFolderItem = NULL;
hr = pFolder2->get_Self(&pFolderItem);
if (SUCCEEDED(hr) && pFolderItem)
{
pFolderItem->put_Name(strNewName);
pFolderItem->Release();
}
pFolder2->Release();
}
pFolder->Release();
}
pShellDispatch->Release();
}
}