アンマネージド プロセスで .NET ランタイムをホストする必要があります。COM 経由でランタイムをロードするコードがあり、アセンブリを AppDomain にロードして、コードを問題なく実行できます。
ただし、ネットワーク共有でホストされているアプリケーションで問題が発生し、それらを実行するためにアプリケーション ポリシーを変更する必要がありますが、これはオプションではありません。そこで、ランタイムのメイン AppDomain のアクセス許可レベルを無制限に設定したいと思います。
AppDomain ポリシー レベルを設定する方法の例を誰か提供できますか? アンマネージド コードから必要なクラスをインスタンス化して PolicyLevel と関連オブジェクトを作成し、ポリシーを設定する方法がよくわかりません。基本的に、使用する C++ コードからこれを機能させるために必要なインクルード/名前空間参照がわかりません。
この時点で私が持っているコードは次のとおりです。
/// Starts up the CLR and creates a Default AppDomain
DWORD WINAPI ClrLoad(char *ErrorMessage, DWORD *dwErrorSize)
{
if (spDefAppDomain)
return 1;
//Retrieve a pointer to the ICorRuntimeHost interface
HRESULT hr = CorBindToRuntimeEx(
ClrVersion, //Retrieve latest version by default
L"wks", //Request a WorkStation build of the CLR
STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | STARTUP_CONCURRENT_GC,
CLSID_CorRuntimeHost,
IID_ICorRuntimeHost,
(void**)&spRuntimeHost
);
if (FAILED(hr))
{
*dwErrorSize = SetError(hr,ErrorMessage);
return hr;
}
//Start the CLR
hr = spRuntimeHost->Start();
if (FAILED(hr))
return hr;
CComPtr<IUnknown> pUnk;
//Retrieve the IUnknown default AppDomain
//hr = spRuntimeHost->GetDefaultDomain(&pUnk);
//if (FAILED(hr))
// return hr;
WCHAR domainId[50];
swprintf(domainId,L"%s_%i",L"wwDotNetBridge",GetTickCount());
hr = spRuntimeHost->CreateDomain(domainId,NULL,&pUnk);
hr = pUnk->QueryInterface(&spDefAppDomain.p);
if (FAILED(hr))
return hr;
// // Create a new AppDomain PolicyLevel.
//PolicyLevel polLevel = PolicyLevel:: CreateAppDomainLevel();
//// Create a new, empty permission set.
// PermissionSet permSet = gcnew PermissionSet( PermissionState::Unrestricted);
//// Add permission to execute code to the permission set.
//permSet->AddPermission( gcnew SecurityPermission( SecurityPermissionFlag::Execution ) );
////// Give the policy level's root code group a new policy statement based
////// on the new permission set.
////polLevel->RootCodeGroup->PolicyStatement = gcnew PolicyStatement( permSet );
//// Give the new policy level to the application domain.
//spDefAppdomain->SetAppDomainPolicy( polLevel );
return 1;
}
必要なことを実行しているように見えるサンプル コード (コメント付き) をいくつかピックアップしましたが、PermissionSet と PolicyLevel の型参照を機能させるために必要な lib/include 参照がわかりません。
どんなアイデアでも大歓迎です...