本文整理汇总了C++中Assembly::LoadTypeHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ Assembly::LoadTypeHandle方法的具体用法?C++ Assembly::LoadTypeHandle怎么用?C++ Assembly::LoadTypeHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assembly
的用法示例。
在下文中一共展示了Assembly::LoadTypeHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateManagedObject
HRESULT STDMETHODCALLTYPE ICorDBPrivHelperImpl::CreateManagedObject(
/*in*/ WCHAR *wszAssemblyName,
/*in*/ WCHAR *wszModuleName,
/*in*/ mdTypeDef classToken,
/*in*/ void *rawData,
/*out*/ IUnknown **ppUnk)
{
_ASSERTE(TypeFromToken((mdTypeDef)classToken) == mdtTypeDef);
_ASSERTE(wszAssemblyName && wszModuleName && ppUnk);
if (!wszAssemblyName || !wszModuleName || classToken == mdTokenNil)
return E_INVALIDARG;
if (!ppUnk)
return E_POINTER;
HRESULT hr = S_OK;
BEGINCANNOTTHROWCOMPLUSEXCEPTION();
// This will set up a managed thread object if one does not already exist
// for this particular thread.
Thread* pThread = SetupThread();
if (pThread == NULL) {
hr = E_OUTOFMEMORY;
goto Exit;
}
// Start up COM Interop
if (FAILED(hr = QuickCOMStartup()))
goto Exit;
{
// Don't want to be interrupted...
BOOL fWasGCEnabled = !pThread->PreemptiveGCDisabled();
if (fWasGCEnabled)
pThread->DisablePreemptiveGC();
Assembly *pAssembly;
Module *pModule;
if (GetAppDomain() == NULL)
hr = E_INVALIDARG;
else
{
// Try and load the assembly, given the name provided.
OBJECTREF pThrowable = NULL;
GCPROTECT_BEGIN(pThrowable);
hr = AssemblySpec::LoadAssembly(wszAssemblyName, &pAssembly, &pThrowable);
GCPROTECT_END();
if (SUCCEEDED(hr))
{
_ASSERTE(pAssembly);
// Try and load the module, given the name provided.
hr = pAssembly->GetModuleFromFilename(wszModuleName, &pModule);
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))
{
//.........这里部分代码省略.........