動作環境
C++ Builder XE4
Unit2.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::B_checkRecycleBinClick(TObject *Sender)
{
//LPTSTR getPath[255];
wchar_t appdata[255];
SHGetSpecialFolderPath(NULL, appdata, CSIDL_APPDATA, false);
OutputDebugString(appdata);
wchar_t recycle[255];
SHGetSpecialFolderPath(NULL, recycle, CSIDL_BITBUCKET, false);
OutputDebugString(recycle);
}
//---------------------------------------------------------------------------
デバッグ出力: C:\Users\XXX\AppData\Roaming プロセス Project1.exe (1852)
デバッグ出力: [化けた文字] プロセス Project1.exe (1852)
(追記 2017/10/18)
ゴミ箱のPItemIDListは取得できるが、実際のパスは取得できない、というようなコメントが付いた。自分が検索して読んだ情報でも似たような情報で、実際に試した結果もそのようであった。
ごみ箱: special group of objects
http://computer-programming-forum.com/82-mfc/eb60eae5f2e5ac99.htm
の
Mark Henr #8/9
あたりを見ていると、ごみ箱は特殊なグループに属するようだ。
それを読むには色々しないといけないようだ。
固定文字列実装
Unit3.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
String recycleBin = L"C:\\$Recycle.Bin";
ShellExecute(NULL, NULL, L"explorer.exe", recycleBin.c_str(), NULL, SW_SHOWNORMAL);
}
//--
上記の実装で以下の環境でゴミ箱が開いた。
- Windows 7 pro (32bit)
- Windows 8.1 pro (64bit)
- Windows 10 pro (64bit)
固定文字列だと将来のOSに対応できない可能性がある。