|
// This is the main project file for VC++ Windows Service project
#include "stdafx.h"
#include <string.h>
#include "CLRMHostWinService.h"
using namespace CLRMHost;
using namespace System::Text;
#import <RemoteObjectLoader.tlb> raw_interfaces_only high_property_prefixes("_get","_put","_putref")
//To install the service, type: "CLRMHost.exe -i"
int _tmain(int argc, _TCHAR* argv[])
{
if (argc >= 2)
{
if (argv[1][0] == _T('/'))
{
argv[1][0] = _T('-');
}
if (_tcsicmp(argv[1], _T("-i")) == 0)
{
//Install this Windows Service using InstallUtil.exe
String* myargs[] = System::Environment::GetCommandLineArgs();
String* args[] = new String*[myargs->Length - 1];
args[0] = (myargs[0]);
Array::Copy(myargs, 2, args, 1, args->Length - 1);
AppDomain* dom = AppDomain::CreateDomain(S"execDom");
Type* type = __typeof(System::Object);
String* path = type->get_Assembly()->get_Location();
StringBuilder* sb = new StringBuilder(path->Substring(0, path->LastIndexOf(S"\\")));
sb->Append(S"\\InstallUtil.exe");
dom->ExecuteAssembly(sb->ToString(), 0, args);
}
}
else
{
ServiceBase::Run(new CLRMHostWinService());
}
return 0;
}
ICorRuntimeHost *pHost =NULL;
void CLRMHostWinService::Load()
{
LPWSTR pszVer = L"v1.0.2204";
LPWSTR pszFlavor = L"wks"; // svr, wks
HRESULT hr = CorBindToRuntimeEx(pszVer, pszFlavor,
STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC,
CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void **)&pHost);
pHost->Start();
mscorlib::_AppDomain *pDefaultDomain = NULL;
IUnknown *pAppDomainPunk = NULL;
hr = pHost->GetDefaultDomain(&pAppDomainPunk);
hr = pAppDomainPunk->QueryInterface(__uuidof(mscorlib::_AppDomain),
(void**) &pDefaultDomain);
//
// Load the managed portion of our host into the default domain.
//
JQD::RemoteObjectLoader *pRemotingHost=NULL;
mscorlib::_ObjectHandle *pObjHandle = NULL;
hr = pDefaultDomain->CreateInstance(
_bstr_t("RemoteObjectLoader"),
_bstr_t("JQD.RemoteObjectLoader"),
&pObjHandle);
VARIANT v;
VariantInit(&v);
hr = pObjHandle->Unwrap(&v);
hr = v.pdispVal->QueryInterface(__uuidof(RemoteObjectLoader::_RemoteObjectLoader),
(void**) &pRemotingHost);
// pRemotingHost->Load();
pRemotingHost->LoadTestOnly();
pAppDomainPunk->Release();
pDefaultDomain->Release();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a Microsoft Certified Application Developer (MCAD), currently focusing on using .Net Framework to develop Business Solutions. I am mostly language neutral. I have used C, C++, ATL, MFC, VB.Net, C#, VB 6, PL/SQL, Transact SQL, ASP, Fortran, etc.