/*
* CertSystemStoreEnum.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/04/06
#pragma once
#include <sol/Object.h>
#include <wincrypt.h>
#include <locale.h>
#pragma comment (lib, "crypt32.lib")
/*
CERT_SYSTEM_STORE_CURRENT_USER
CERT_SYSTEM_STORE_LOCAL_MACHINE
CERT_SYSTEM_STORE_CURRENT_SERVICE
*/
namespace SOL {
class CertSystemStoreEnum : public Object {
public:
/**
* Constructor
*/
CertSystemStoreEnum()
{
//Use SOL;;Locale class
//_tsetlocale(LC_ALL, lang); // "Japanese_Japan.20932";
}
protected:
/**
* This is a virtual method which can be called from static method enumCallback.
* This simply shows a storeName and a localized name of each enumerated store.
*/
virtual BOOL enumStore(const void *pvSystemStore,
DWORD dwFlags,
PCERT_SYSTEM_STORE_INFO pStoreInfo)
{
const wchar_t* systemStore = (const wchar_t*)pvSystemStore;
const wchar_t* name = CryptFindLocalizedName(systemStore);
if (systemStore && wcslen(systemStore)>0 && name) {
wprintf(L"%s (%s)\n", systemStore, name);
}
return TRUE;
}
public:
/**
*/
void enumerate(DWORD dwFlags = CERT_SYSTEM_STORE_CURRENT_USER)
{
CertEnumSystemStore(dwFlags, NULL, this, enumCallback);
}
private:
static BOOL WINAPI enumCallback(const void *pvSystemStore,
DWORD dwFlags,
PCERT_SYSTEM_STORE_INFO pStoreInfo,
void *pvReserved,
void *pvArg)
{
BOOL rc = FALSE;
CertSystemStoreEnum* storeEnum = (CertSystemStoreEnum*)pvArg;
if (storeEnum) {
// Call protected virtual method enumStore.
rc =storeEnum -> enumStore(pvSystemStore, dwFlags, pStoreInfo);
}
return rc;
}
};
}
|