//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "atlsafe.h"
#import <mscorlib.tlb> raw_interfaces_only rename("ReportEvent","ReportEventManaged")
#include <metahost.h>
#pragma comment(lib,"mscoree.lib")
#include <mscoree.h>
#include <comdef.h>
using namespace mscorlib;
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CGetMgdFromNativeApp : public AcRxArxApp {
public:
CGetMgdFromNativeApp() : AcRxArxApp() {}
virtual AcRx::AppRetCode On_kInitAppMsg(void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
return (retCode);
}
virtual AcRx::AppRetCode On_kUnloadAppMsg(void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
return (retCode);
}
virtual void RegisterServerComponents() {
//----- Self-register COM server upon loading.
if (FAILED(::DllRegisterServer()))
acutPrintf(_RXST("Failed to register COM server.\n"));
}
static void RivilisGetManagedDlls() {
// Put your command code here
CComPtr<ICLRMetaHost> spClrMetaHost;
// get a MetaHost
HRESULT hr = CLRCreateInstance(
CLSID_CLRMetaHost,
IID_PPV_ARGS(&spClrMetaHost)
);
_ASSERT(hr == S_OK);
// get a particular runtime version
CComPtr<ICLRRuntimeInfo> spCLRRuntimeInfo;
hr = spClrMetaHost->GetRuntime(L"v4.0.30319",
IID_PPV_ARGS(&spCLRRuntimeInfo)
);
_ASSERT(hr == S_OK);
// get the CorRuntimeHost
CComPtr<ICorRuntimeHost> spCorRuntimeHost;
hr = spCLRRuntimeInfo->GetInterface(
CLSID_CorRuntimeHost,
IID_PPV_ARGS(&spCorRuntimeHost)
);
_ASSERT(hr == S_OK);
// Start the CLR
hr = spCorRuntimeHost->Start();
_ASSERT(hr == S_OK);
// get the Default app domain as an IUnknown
CComPtr<IUnknown> spAppDomainThunk;
hr = spCorRuntimeHost->GetDefaultDomain(&spAppDomainThunk);
_ASSERT(hr == S_OK);
// convert the Appdomain IUnknown to a _AppDomain
CComPtr<_AppDomain> spAppDomain;
hr = spAppDomainThunk->QueryInterface(IID_PPV_ARGS(&spAppDomain));
_ASSERT(hr == S_OK);
SAFEARRAY *pAssemblyArray = NULL;
hr = spAppDomain->GetAssemblies(&pAssemblyArray);
_ASSERT(hr == S_OK);
CComSafeArray<IUnknown*> csaAssemblies;
csaAssemblies.Attach(pAssemblyArray);
long cAssemblies = csaAssemblies.GetCount();
for (long i = 0; i < cAssemblies; i++)
{
CComPtr<_Assembly> spAssembly;
spAssembly = csaAssemblies[i];
if (spAssembly == NULL)
continue;
CComBSTR asmFullName;
hr = spAssembly->get_FullName(&asmFullName);
if (FAILED(hr))
continue;
acutPrintf(L"\nFull Name:%s", asmFullName);
CComBSTR asmLocatation;
hr = spAssembly->get_Location(&asmLocatation);
if (!FAILED(hr))
acutPrintf(L"\n\tLocation: %s", asmLocatation);
else
acutPrintf(L"\n\tLocation not found");
}
hr = spCorRuntimeHost->Stop();
_ASSERT(hr == S_OK);
}
};
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CGetMgdFromNativeApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CGetMgdFromNativeApp, Rivilis, GetManagedDlls, GetManagedDlls, ACRX_CMD_MODAL, NULL)