CE系OSでストレージデバイスのボリューム名称を取得する方法

CE系OSでストレージデバイスのボリューム名称を取得する方法です。
USBメモリとかSDカードをマウントした時に表示されるボリューム(ドライブ)名称のことです。

レジストリを参照すると使用される基本名称まではわかるのですが、同じデバイスが2つ目以降につけられる数字まではわかりませんので下記のAPIを使用します。

標準的じゃないと思われるAPIを使用します。
「storemgr.h」のインクルードと、「Storeapi.lib」をリンクしてください。
ただし、STANDARDSDK 5.0には、含まれてません。PlatformBuilderのインストールされている 環境にしかないようです。 具体的な場所は「c:\wince500」の下のほうにありますので検索してください。
使用方法事態は非常に簡単です。

早速サンプルです。
#include <storemgr.h>
#include <tchar.h>

void test()
{
STOREINFO si = {0};
PARTINFO pi = {0};
HANDLE hFind = INVALID_HANDLE_VALUE;
HANDLE hFindPart = INVALID_HANDLE_VALUE;
HANDLE hStore = INVALID_HANDLE_VALUE;

si.cbSize = sizeof(STOREINFO);
pi.cbSize = sizeof(PARTINFO);

// ストレージの検索
hFind = FindFirstStore(&si);
if(INVALID_HANDLE_VALUE != hFind){
do{
_tprintf(TEXT(">--- ストレージの情報\n"));
_tprintf(TEXT("szDevieceName : %s\n"),si.szDeviceName);
_tprintf(TEXT("szStoreName : %s\n"),si.szStoreName);
_tprintf(TEXT("dwDeviceFlags : %d\n"),si.dwDeviceFlags);
_tprintf(TEXT("dwPartitionCount : %d\n"),si.dwPartitionCount);
_tprintf(TEXT("dwMountCount : %d\n"),si.dwMountCount);
_tprintf(TEXT("profile : %s\n"),si.sdi.szProfile);
_tprintf(TEXT("Size(kByte) : %d\n"),(int)(si.snNumSectors * si.dwBytesPerSector / 1024));

//ストレージハンドルを開く
hStore = OpenStore(si.szDeviceName);//ストレージのハンドルを開く
if(hStore != INVALID_HANDLE_VALUE){
//パーティションの検索
hFindPart = FindFirstPartition(hStore,&pi);
if(hFindPart != INVALID_HANDLE_VALUE){
do{
_tprintf(TEXT(">--- パーティション情報\n"));
_tprintf(TEXT("szPartitionName : %s\n"),pi.szPartitionName);
_tprintf(TEXT("szFileSys : %s\n"),pi.szFileSys);
_tprintf(TEXT("szVolumeName : %s\n"),pi.szVolumeName);
}while(FindNextPartition(hFindPart,&pi));
FindClosePartition(hFindPart);
}
CloseHandle(hStore);
}
}while(FindNextStore(hFind, &si));
FindClose(hFind);
}
}
ポイントになるAPIと構造体
STOREINFO : ストレージに関する情報
PARTINFO : パーティションに関する情報
FindFirstStore(...)
OpenStore(...)
FindNextStore(...)
FindClose(...)
FindFirstPartition(...)
FindNextPartition(...)
FindClosePartition(...)
基本的な使い方はファイル検索のFindFirstと同様ですので簡単だと思います。