Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 4-7 extracted from chapter The CLR (Common Languages Runtime)


Listing 4-6<     > Listing 4-8



Example_4_7.cpp
// You need to link with the static lib mscoree.lib 
// to compile this C++ file.
#include <mscoree.h>

// The import must be done on a single line. 
#import <mscorlib.tlb> raw_interfaces_only ...
  ... high_property_prefixes("_get","_put","_putref") ... 
    ... rename("ReportEvent","ReportEventManaged") rename_namespace("CRL")

// We use the namespace ComRuntimeLibrary.
using namespace CRL;
ICLRRuntimeHost * pClrHost = NULL;

void main (void){
   // Get a COM pointer of type ICorRuntimeHost on the CLR.
   HRESULT hr CorBindToRuntimeEx(
               NULL// We ask for the most recent version of the CLR.
               NULL// We ask for the workstation version of the CLR.
               0, 
               CLSID_CLRRuntimeHost,
               IID_ICLRRuntimeHost, 
               (LPVOID *) &pClrHost);
   if (FAILED(hr)){
      printf("Can't get a pointer of type ICLRRuntimeHost!");
      return;
   }
   printf("We got a pointer of type ICCLRRuntimeHost.\n");
   printf("Launch the CLR.\n");
   pClrHost->Start();

   // Here, we can use our COM pointer pClrHost on the CLR.

   pClrHost->Stop();
   printf("CLR stopped.\n");
   pClrHost->Release();
   printf("Bye!\n");
}	
Copyright Patrick Smacchia 2006 2007