Click here to Skip to main content
15,886,788 members
Articles / Desktop Programming / ATL

TCP Remoting Windows Service Host with Server GC

Rate me:
Please Sign up or sign in to vote.
3.40/5 (3 votes)
14 Apr 2004CPOL4 min read 67.5K   690   20  
Implement Server GC for TCP Remoting Host.
// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>

#import <RemoteObjectLoader.tlb> raw_interfaces_only high_property_prefixes("_get","_put","_putref")

using namespace System;

int _tmain()
{

	LPWSTR pszVer = L"v1.0.2204";
	LPWSTR pszFlavor = L"wks";  // svr, wks
	ICorRuntimeHost *pHost = NULL;

	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 *pMgdHost=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**) &pMgdHost);
	//assert(pMgdHost);

	pMgdHost->Load();

	pAppDomainPunk->Release();
	pDefaultDomain->Release();

	pHost->Stop();	 
	Console::ReadLine();
	return 0;
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
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.

Comments and Discussions