G
Guest
In hosting the CLR I would like to create a new AppDomain the will be created with some "Evidence" that I supply it. I want my evidence to contain two class objects from the System.Security.Policy namespace. These are the Url and Zone classes. I can successfully create the Url class as it takes a string with the desired UrlName as the single argument to constructor. When I try to create the Zone class, which takes a System.Security.SecurityZone enum as the single arguement to it's constructor, I get an HRESULT error 0x80131513 (MissingMethodException). I'm passing the enum as a VT_I4 type variant. Would anyone know why this doesn't work? My simplified code example to just create the Url and Zone classes is included here below
Thanks
Bob Elwar
#include "stdafx.h
/
#import <mscorlib.tlb> raw_interfaces_only raw_interfaces_only high_property_prefixes("_get","_put","_putref") rename("ReportEvent", "_ReportEvent"
using namespace mscorlib
/
int main(int argc, char* argv[]
HRESULT hr
LPWSTR psClrVer = NULL; // E.g., L"v1.1.4322
LPWSTR pszWKSorSVR = L"svr"; // L"wks
ICorRuntimeHost *pHost = NULL
/
hr = CorBindToRuntimeEx(psClrVer,pszWKSorSVR,STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN| STARTUP_CONCURRENT_GC,CLSID_CorRuntimeHost,IID_ICorRuntimeHost,(void **)&pHost)
assert(SUCCEEDED(hr));
/
hr = pHost->Start()
assert(SUCCEEDED(hr))
/
IUnknown *punkAppDomain = NULL
hr = pHost->GetDefaultDomain(&punkAppDomain)
assert(SUCCEEDED(hr));
/
_AppDomain *pDefaultAppDomain = NULL
hr = punkAppDomain->QueryInterface(__uuidof(_AppDomain),(void**) &pDefaultAppDomain)
assert(SUCCEEDED(hr));
// Strings for CreateInstance_
BSTR asmUrlName = SysAllocString(L"mscorlib")
BSTR typeUrlName = SysAllocString(L"System.Security.Policy.Url")
// Create a variant BSTR to hold the Url name strin
VARIANT vUrlParam
VariantInit(&vUrlParam)
vUrlParam.vt = VT_BSTR
vUrlParam.bstrVal = SysAllocString(L"http://www.MyDomain.com/")
// Create a 1D array with one string elemen
SAFEARRAY* pUrlSAFEARRAY = SafeArrayCreateVector(VT_VARIANT, 0, 1)
LONG lngUrlIndex = 0
hr = SafeArrayPutElement(pUrlSAFEARRAY, &lngUrlIndex, &vUrlParam)
assert(SUCCEEDED(hr));
// Create an instance of Url using a parameterized constructo
_ObjectHandle* pUrlObjHandle
hr = pDefaultAppDomain->CreateInstance_3(asmUrlName, typeUrlName, VARIANT_TRUE, BindingFlags_Default, NULL, pUrlSAFEARRAY, NULL, NULL, NULL, &pUrlObjHandle)
assert(SUCCEEDED(hr));
// Strings for CreateInstance_
BSTR asmZoneName = SysAllocString(L"mscorlib")
BSTR typeZoneName = SysAllocString(L"System.Security.Policy.Zone")
// Create a variant I4 to hold the Zone Enu
VARIANT vZoneParam
VariantInit(&vZoneParam)
vZoneParam.vt = VT_I4
vZoneParam.lVal = SecurityZone_Internet
// Create a 1D array with one string elemen
SAFEARRAY* pZoneSAFEARRAY = SafeArrayCreateVector(VT_VARIANT, 0, 1)
LONG lngZoneIndex = 0
hr = SafeArrayPutElement(pZoneSAFEARRAY, &lngZoneIndex, &vZoneParam)
assert(SUCCEEDED(hr));
// Create an instance of Url using a parameterized constructo
_ObjectHandle* pZoneObjHandle
hr = pDefaultAppDomain->CreateInstance_3(asmZoneName, typeZoneName, VARIANT_TRUE, BindingFlags_Default, NULL, pZoneSAFEARRAY, NULL, NULL, NULL, &pZoneObjHandle)
assert(SUCCEEDED(hr));
/
return 0
Thanks
Bob Elwar
#include "stdafx.h
/
#import <mscorlib.tlb> raw_interfaces_only raw_interfaces_only high_property_prefixes("_get","_put","_putref") rename("ReportEvent", "_ReportEvent"
using namespace mscorlib
/
int main(int argc, char* argv[]
HRESULT hr
LPWSTR psClrVer = NULL; // E.g., L"v1.1.4322
LPWSTR pszWKSorSVR = L"svr"; // L"wks
ICorRuntimeHost *pHost = NULL
/
hr = CorBindToRuntimeEx(psClrVer,pszWKSorSVR,STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN| STARTUP_CONCURRENT_GC,CLSID_CorRuntimeHost,IID_ICorRuntimeHost,(void **)&pHost)
assert(SUCCEEDED(hr));
/
hr = pHost->Start()
assert(SUCCEEDED(hr))
/
IUnknown *punkAppDomain = NULL
hr = pHost->GetDefaultDomain(&punkAppDomain)
assert(SUCCEEDED(hr));
/
_AppDomain *pDefaultAppDomain = NULL
hr = punkAppDomain->QueryInterface(__uuidof(_AppDomain),(void**) &pDefaultAppDomain)
assert(SUCCEEDED(hr));
// Strings for CreateInstance_
BSTR asmUrlName = SysAllocString(L"mscorlib")
BSTR typeUrlName = SysAllocString(L"System.Security.Policy.Url")
// Create a variant BSTR to hold the Url name strin
VARIANT vUrlParam
VariantInit(&vUrlParam)
vUrlParam.vt = VT_BSTR
vUrlParam.bstrVal = SysAllocString(L"http://www.MyDomain.com/")
// Create a 1D array with one string elemen
SAFEARRAY* pUrlSAFEARRAY = SafeArrayCreateVector(VT_VARIANT, 0, 1)
LONG lngUrlIndex = 0
hr = SafeArrayPutElement(pUrlSAFEARRAY, &lngUrlIndex, &vUrlParam)
assert(SUCCEEDED(hr));
// Create an instance of Url using a parameterized constructo
_ObjectHandle* pUrlObjHandle
hr = pDefaultAppDomain->CreateInstance_3(asmUrlName, typeUrlName, VARIANT_TRUE, BindingFlags_Default, NULL, pUrlSAFEARRAY, NULL, NULL, NULL, &pUrlObjHandle)
assert(SUCCEEDED(hr));
// Strings for CreateInstance_
BSTR asmZoneName = SysAllocString(L"mscorlib")
BSTR typeZoneName = SysAllocString(L"System.Security.Policy.Zone")
// Create a variant I4 to hold the Zone Enu
VARIANT vZoneParam
VariantInit(&vZoneParam)
vZoneParam.vt = VT_I4
vZoneParam.lVal = SecurityZone_Internet
// Create a 1D array with one string elemen
SAFEARRAY* pZoneSAFEARRAY = SafeArrayCreateVector(VT_VARIANT, 0, 1)
LONG lngZoneIndex = 0
hr = SafeArrayPutElement(pZoneSAFEARRAY, &lngZoneIndex, &vZoneParam)
assert(SUCCEEDED(hr));
// Create an instance of Url using a parameterized constructo
_ObjectHandle* pZoneObjHandle
hr = pDefaultAppDomain->CreateInstance_3(asmZoneName, typeZoneName, VARIANT_TRUE, BindingFlags_Default, NULL, pZoneSAFEARRAY, NULL, NULL, NULL, &pZoneObjHandle)
assert(SUCCEEDED(hr));
/
return 0