/*
* COMInitializer.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
#pragma once
#define _WIN32_DCOM
#include <sol\Object.h>
namespace SOL
{
class COMInitializer :public Object {
public:
/**
* Constructor
*/
COMInitializer() {
HRESULT hr = S_OK;
if (FAILED(hr = CoInitialize(NULL))) {
throw hr;
}
}
public:
/**
* Constructor
*
* @param dwCoInit COM initializer parameter
* // Example: dwCoInit = COINIT_MULTITHREADED
*/
COMInitializer(DWORD dwCoInit) {
HRESULT hr = S_OK;
if (FAILED(hr = CoInitializeEx(NULL, dwCoInit))) {
throw hr;
}
}
public:
/**
* Destructor
*/
~COMInitializer() {
CoUninitialize();
}
public:
/**
* Set Default COM security levels with default authentication and Impersonation.
*/
void setDefaultSecurityLevels() {
HRESULT hr = S_OK;
if (FAILED (hr= CoInitializeSecurity(
NULL,
-1, // COM negotiates service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
))) {
throw hr;
}
}
/*
*/
};
}
|