本文整理汇总了C++中MethodTable::CheckRunClassInit方法的典型用法代码示例。如果您正苦于以下问题:C++ MethodTable::CheckRunClassInit方法的具体用法?C++ MethodTable::CheckRunClassInit怎么用?C++ MethodTable::CheckRunClassInit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodTable
的用法示例。
在下文中一共展示了MethodTable::CheckRunClassInit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateManagedObject
//.........这里部分代码省略.........
if (SUCCEEDED(hr))
{
_ASSERTE(pModule);
// If the class isn't known,then don't try and create it.
if (!pModule->GetMDImport()->IsValidToken(classToken))
hr = E_INVALIDARG;
else
{
COMPLUS_TRY
{
OBJECTREF obj = NULL;
GCPROTECT_BEGIN(obj);
// Now try and get the TypeHandle for the given token
NameHandle nameHandle(pModule, classToken);
TypeHandle typeHandle =
pAssembly->LoadTypeHandle(&nameHandle, &obj);
// If an exception was thrown at some point, convert
// it to an HRESULT
if (obj != NULL)
hr = SecurityHelper::MapToHR(obj);
// No longer need the object, can be GC'd if desired
obj = NULL;
if (SUCCEEDED(hr))
{
_ASSERTE(typeHandle.AsMethodTable());
MethodTable *pMT = typeHandle.AsMethodTable();
if (!pMT->GetClass()->IsValueClass() ||
pMT->ContainsPointers())
hr = CORDBG_E_OBJECT_IS_NOT_COPYABLE_VALUE_CLASS;
if (SUCCEEDED(hr))
{
// Now run the class initialiser
if (!pMT->CheckRunClassInit(&obj))
hr = SecurityHelper::MapToHR(obj);
// No longer need the object, can be GC'd if
// desired
obj = NULL;
if (SUCCEEDED(hr))
{
// If successful, allocate an instance of
// the class
// This may throw an
// OutOfMemoryException, but the below
// COMPLUS_CATCH should handle it. If
// the class is a ValueClass, the
// created object will be a boxed
// ValueClass.
obj = AllocateObject(pMT);
// Now create a COM wrapper around
// this object. Note that this can
// also throw.
*ppUnk = GetComIPFromObjectRef(&obj);
_ASSERTE(ppUnk);
// This is the nasty part. We're gonna
// copy the raw data we're given over
// the new instance of the value
// class...
CopyValueClass(obj->UnBox(), rawData, pMT, obj->GetAppDomain());
// No longer need the object, can be GC'd
// if desired
obj = NULL;
}
}
}
GCPROTECT_END(); // obj
}
COMPLUS_CATCH
{
// If there's an exception, convert it to an HR
hr = SecurityHelper::MapToHR(GETTHROWABLE());
}
COMPLUS_END_CATCH
}
}
}
}
if (fWasGCEnabled)
pThread->EnablePreemptiveGC();
}
Exit:
ENDCANNOTTHROWCOMPLUSEXCEPTION();
return (hr);
}