本文整理汇总了C++中CMyString::Format方法的典型用法代码示例。如果您正苦于以下问题:C++ CMyString::Format方法的具体用法?C++ CMyString::Format怎么用?C++ CMyString::Format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMyString
的用法示例。
在下文中一共展示了CMyString::Format方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deleteClass
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::deleteClass
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::deleteClass(const String& nameSpace,
const String& userName,
const String& password,
const String& className)
{
HRESULT hr;
PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIClassProvider::deleteClass()");
CComPtr<IWbemServices> pServices;
//Connect to namespace
setup(nameSpace,userName,password);
bool bConnected = _collector->Connect(&pServices);
if (!bConnected)
{
if (pServices)
pServices.Release();
throw CIMException(CIM_ERR_ACCESS_DENIED);
}
//Convert the parameters to make the WMI call
CComBSTR bsClassName = className.getCString();
LONG lFlags = 0L;
//Perform the WMI operation
hr = pServices->DeleteClass(bsClassName,
lFlags,
NULL,
NULL);
if (pServices)
pServices.Release();
//Handle the WMI operation result
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to delete class [%s]. Error: 0x%X", 255, className.getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::deleteClass() - %s", (LPCTSTR)msg);
switch (hr)
{
case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
case WBEM_E_FAILED: throw CIMException(CIM_ERR_FAILED); break;
case WBEM_E_INVALID_PARAMETER: throw CIMException(CIM_ERR_FAILED, "WMI Invalid Parameter"); break;
case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_NOT_FOUND); break;
case WBEM_E_NOT_FOUND: throw CIMException(CIM_ERR_NOT_FOUND); break;
case WBEM_E_CLASS_HAS_CHILDREN: throw CIMException(CIM_ERR_CLASS_HAS_CHILDREN); break;
default: throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
}
PEG_METHOD_EXIT();
}
示例2: createQualifier
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createQualifier creates a qualifiers
//
/////////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createQualifier (const WMIQualifier &qualifier,
IWbemQualifierSet *pQual)
{
HRESULT hr;
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createQualifier()");
String sName = qualifier.getName().getString();
CComBSTR bs = sName.getCString();
WMIValue value(qualifier.getValue());
WMIFlavor flavor(qualifier.getFlavor());
CComVariant v;
value.getAsVariant(&v);
// key is created using a special call to wmi
//if (!stricmp("key", ))
if (String::equalNoCase("key", sName))
{
hr = pQual->Put(bs, &v, NULL);
}
else
{
hr = pQual->Put(bs, &v, flavor.getAsWMIValue());
}
v.Clear();
bs.Empty();
if (FAILED(hr))
{
CMyString msg;
msg.Format("It is not possible to add the qualifier [%s] to "
"the object! Error: 0x%X", 255, sName.getCString(), hr);
PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1,
"WmiClassProvider::createQualifier() - %s", (LPCTSTR)msg));
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
PEG_METHOD_EXIT();
return;
}
示例3: createProperty
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createProperty creates one property
// doesn't create the qualifiers
/////////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createProperty(const CIMProperty &keyProp,
IWbemClassObject *pNewClass)
{
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createProperty()");
// create the property
//Get the CIMTYPE of the parameter
CIMTYPE type = CIMTypeToWMIType(keyProp.getType());
//If the property is an array, add CIM_FLAG_ARRAY to CIMType
if (keyProp.isArray())
{
type |= CIM_FLAG_ARRAY;
}
// add the property to the class
CComBSTR bs = keyProp.getName().getString().getCString();
HRESULT hr = pNewClass->Put(bs, NULL, NULL, type);
bs.Empty();
//handle the error, if failed
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to add property [%s]. Error: 0x%X", 255,
keyProp.getName().getString().getCString(), hr);
PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1,
"WMIClassProvider::createProperty () - %s",
(LPCTSTR)msg));
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
PEG_METHOD_EXIT();
return;
}
示例4: createProperties
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createProperties creates all properties including keys
// add the qualifiers too
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createProperties(const CIMClass& newClass,
IWbemServices *pServices,
IWbemClassObject *pNewClass)
{
HRESULT hr;
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createProperties()");
// create the properties but don't create the keys again
CIMProperty prop;
for (Uint32 i = 0; i < newClass.getPropertyCount(); i++)
{
prop = newClass.getProperty(i).clone();
// create the properties
try
{
createProperty(prop, pNewClass);
}
catch (CIMException&)
{
throw;
}
// get a pointer to work with qualifiers
CComPtr<IWbemQualifierSet> pQual;
CComBSTR bs = prop.getName().getString().getCString();
hr = pNewClass->GetPropertyQualifierSet(bs, &pQual);
bs.Empty();
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed get Qualifier set of [%s]. Error: 0x%X", 255,
prop.getName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createProperties() - %s", (LPCTSTR)msg);
if (pQual)
pQual.Release();
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
// set the qualifiers to the property
for (Uint32 j = 0; j < prop.getQualifierCount(); j++)
{
WMIQualifier qualifier(prop.getQualifier(j));
try
{
createQualifier(qualifier, pQual);
}
catch (CIMException&)
{
if (pQual)
pQual.Release();
throw;
}
}
// set the CLASSORIGIN qualifier if it wasn't set yet
String strClassorigin = prop.getClassOrigin().getString();
if (strClassorigin.size() == 0)
{
strClassorigin = newClass.getClassName().getString();
}
WMIFlavor flavor(CIMFlavor::DEFAULTS);
/*
v.vt = VT_BSTR;
v.bstrVal = strClassorigin.getCString();
*/
CComVariant v;
v = strClassorigin.getCString();
hr = pQual->Put(L"CLASSORIGIN", &v, flavor.getAsWMIValue());
v.Clear();
if (pQual)
pQual.Release();
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to add CLASSORIGIN qualifier in [%s]. Error: 0x%X", 255,
prop.getName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createProperties () - %s", (LPCTSTR)msg);
//.........这里部分代码省略.........
示例5: createClassNameAndClassQualifiers
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createClassNameAndClassQualifiers
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createClassNameAndClassQualifiers(const CIMClass& newClass,
IWbemServices *pServices,
IWbemClassObject **pNewClass,
const bool hasSuperClass)
{
HRESULT hr;
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClassNameAndClassQualifiers()");
// if the class has a superclass, we need to spwan a derived
if (hasSuperClass)
{
// get the superclass name
CComPtr<IWbemClassObject> pSuperClass;
String tmp = newClass.getSuperClassName().getString();
CComBSTR bs = tmp.getCString();
hr = pServices->GetObject(
bs,
NULL,
NULL,
&pSuperClass,
NULL);
bs.Empty();
if (FAILED(hr))
{
if (pSuperClass)
pSuperClass.Release();
CMyString msg;
msg.Format("Failed to get a pointer to Superclass [%s]. Error: 0x%X", 255, tmp.getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
//Creates the new class
pSuperClass->SpawnDerivedClass(NULL, pNewClass);
if (pSuperClass)
pSuperClass.Release();
}
else
{
// we are creating a base class
hr = pServices->GetObject(NULL,
NULL,
NULL,
pNewClass,
NULL);
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to get a pointer to a new class. Error: 0x%X", hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
}
// create the class name
CComVariant v;
v = newClass.getClassName().getString().getCString();
hr = (*pNewClass)->Put(L"__CLASS", 0, &v, 0);
v.Clear();
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to add class name on class [%s]. Error: 0x%X", 255,
newClass.getClassName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
if (*pNewClass)
(*pNewClass)->Release();
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
// get a pointer to work with qualifiers
CComPtr<IWbemQualifierSet> pNewClassQualifier;
hr = (*pNewClass)->GetQualifierSet(&pNewClassQualifier);
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to get the Qualifier set pointer of class [%s]. Error: 0x%X", 255,
//.........这里部分代码省略.........
示例6: createClass
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createClass
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createClass(const String& nameSpace,
const String& userName,
const String& password,
const CIMClass& newClass,
Boolean updateClass)
{
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClass()");
setup(nameSpace, userName, password);
if (!m_bInitialized)
{
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createClass - m_bInitilized= %x, throw CIM_ERR_FAILED exception",
m_bInitialized);
throw CIMException(CIM_ERR_FAILED);
}
// Check if the class does not exist and if if has a valid
// superclass
performInitialCheck(newClass, updateClass);
bool hasSuperClass = (newClass.getSuperClassName().getString() != String::EMPTY);
// gets the pointers
CComPtr<IWbemServices> pServices;
CComPtr<IWbemClassObject> pNewClass;
if (!_collector->Connect(&pServices))
{
if (pServices)
pServices.Release();
throw CIMException (CIM_ERR_FAILED);
}
try
{
// starts the class creation by name and class qualifiers
createClassNameAndClassQualifiers(
newClass,
pServices,
&pNewClass,
hasSuperClass);
// create properties
createProperties(
newClass,
pServices,
pNewClass);
// create methods
createMethods(
newClass,
pServices,
pNewClass);
}
catch (CIMException&)
{
if (pServices)
pServices.Release();
if (pNewClass)
pNewClass.Release();
throw;
}
// Store the new class into WMI
LONG lFlags = 0L;
//if updateClass is set, we are trying a modifyclass
if (updateClass) lFlags = WBEM_FLAG_UPDATE_ONLY;
HRESULT hr = pServices->PutClass(pNewClass, lFlags, NULL, NULL);
if (pServices)
pServices.Release();
if (pNewClass)
pNewClass.Release();
if (FAILED(hr))
{
CMyString msg;
msg.Format("It is not possible to create the class [%s]. Error: 0x%X", 255,
newClass.getClassName().getString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createClass() - %s", (LPCTSTR)msg);
switch(hr)
{
case E_ACCESSDENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
//.........这里部分代码省略.........
示例7: createParam
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createParam create a parameter
//
/////////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createParam(const CIMConstParameter ¶m,
IWbemClassObject *pNewClass)
{
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createParam()");
//Get the CIMTYPE of the parameter
CIMTYPE type = CIMTypeToWMIType(param.getType());
//If the property is an array, add CIM_FLAG_ARRAY to CIMType
if (param.isArray())
{
type |= CIM_FLAG_ARRAY;
}
// add the property to the class
CComBSTR bs = param.getName().getString().getCString();
HRESULT hr = pNewClass->Put(bs, NULL, NULL, type);
//handle the error, if failed
if (FAILED(hr))
{
CMyString msg;
msg.Format("It is not possible to add parameter [%s] to the parameters list! Error: 0x%X", 255,
param.getName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createParam() - %s", (LPCTSTR)msg);
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
// create the qualifiers for this parameter
// get a pointer to work with qualifiers
CComPtr<IWbemQualifierSet> pQual;
hr = pNewClass->GetPropertyQualifierSet(bs, &pQual);
if (FAILED(hr))
{
CMyString msg;
msg.Format("It is not possible to get a qualifier set for parameter [%s]! Error: 0x%X", 255,
param.getName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createParam() - %s", (LPCTSTR)msg);
if (pQual)
pQual.Release();
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
// create the qualifiers for this parameter
for (Uint32 i = 0; i < param.getQualifierCount(); i++)
{
CIMQualifier cimQual = param.getQualifier(i).clone();
WMIQualifier qualifier(cimQual);
try
{
createQualifier(qualifier, pQual);
}
catch (CIMException&)
{
if (pQual)
pQual.Release();
throw;
}
}
if (pQual)
pQual.Release();
PEG_METHOD_EXIT();
return;
}
示例8: createMethod
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createMethod create a method
//
/////////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createMethod (CIMConstMethod &method,
IWbemServices *pServices,
IWbemClassObject *pNewClass)
{
PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createMethod()");
// the parameters
HRESULT hr = S_OK;
CComPtr<IWbemClassObject> pinParameters;
CComPtr<IWbemClassObject> poutParameters;
// Get pointers to use for in & out params:
hr = pServices->GetObject(L"__PARAMETERS",
NULL,
NULL,
&pinParameters,
NULL);
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to get a paramter pointer while creating method: %s! Error: 0x%X",
255, method.getName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createMethod() - %s", (LPCTSTR)msg);
if (pinParameters)
pinParameters.Release();
if (poutParameters)
poutParameters.Release();
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
// Get pointers to use for in & out params:
hr = pServices->GetObject(L"__PARAMETERS",
NULL,
NULL,
&poutParameters,
NULL);
if (FAILED(hr))
{
CMyString msg;
msg.Format("Failed to get a paramter pointer while creating method: %s! Error: 0x%X",
255, method.getName().getString().getCString(), hr);
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIClassProvider::createMethod() - %s", (LPCTSTR)msg);
if (pinParameters)
pinParameters.Release();
if (poutParameters)
poutParameters.Release();
throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
}
// create the parameters
for (Uint32 i = 0; i < method.getParameterCount(); i++)
{
CIMConstParameter param;
param = method.getParameter(i);
// Is this an in or out parameter, or both?
if (param.findQualifier(CIMName("in")) != -1)
{
try
{
createParam(param, pinParameters);
}
catch (CIMException&)
{
if (pinParameters)
pinParameters.Release();
if (poutParameters)
poutParameters.Release();
throw;
}
}
if (param.findQualifier(CIMName("out")) != -1)
{
try
{
createParam(param, poutParameters);
}
catch (CIMException&)
{
if (pinParameters)
pinParameters.Release();
if (poutParameters)
poutParameters.Release();
throw;
//.........这里部分代码省略.........
示例9: getQueryString
//////////////////////////////////////////////////////////////////////////////
// WMIBaseProvider::getQueryString - builds the query string from the
// input parameters for Associator and Reference commands
//
// ///////////////////////////////////////////////////////////////////////////
String WMIBaseProvider::getQueryString(const CIMObjectPath &objectName,
const String &sQueryCommand,
const String &assocClass,
const String &resultClass,
const String &role,
const String &resultRole)
{
bool hasWHERE = false;
bool isInst;
//first we need to get the object name
String sObjName = getObjectName(objectName);
// check if is an instance name
Uint32 pos = sObjName.find(qString(Q_PERIOD));
isInst = (PEG_NOT_FOUND != pos);
CMyString sQuery;
sQuery.Format(CMyString(sQueryCommand), 128, CMyString(sObjName));
//set up any optional parameters
if (!((0 == assocClass.size()) && (0 == resultClass.size()) &&
(0 == role.size()) && (0 == resultRole.size())))
{
// we have optional parameters, append the appropriate ones
sQuery += qChar(Q_WHERE);
hasWHERE = true;
if (0 != assocClass.size())
{
sQuery += qChar(Q_ASSOC_CLS);
sQuery += assocClass;
}
if (0 != resultClass.size())
{
sQuery += qChar(Q_RESULT_CLASS);
sQuery += resultClass;
}
if (0 != role.size())
{
sQuery += qChar(Q_ROLE);
sQuery += role;
}
if (0 != resultRole.size())
{
sQuery += qChar(Q_RESULT_ROLE);
sQuery += resultRole;
}
}
// check if an instance
if (!isInst)
{
// have a class, add "SchemaOnly"
if (!hasWHERE)
{
sQuery += qChar(Q_WHERE);
}
sQuery += qChar(Q_SCHEMA);
}
Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
"WMIBaseProvider::getQueryString() - Query is %s", (LPCTSTR)sQuery);
String s = (LPCTSTR)sQuery;
return s;
}