Previous Table of Contents Next


19.11.1 Mapping the OMG Naming Service to Automation


   This section provides an example of how a standard OMG Object Service, the Naming Service, would be mapped according to the Interworking specification.

   The Naming Service provides a standard service for CORBA applications to obtain object references. The reference for the Naming Service is found by using the resolve_initial_references method provided on the ORB pseudo-interface:

   CORBA::ORB_ptr theORB = CORBA::ORB_init(argc, argv, CORBA::ORBid, ev) CORBA::Object_var obj =

   theORB->resolve_initial_references(“NameService?, ev); CosNaming::NamingContext_var inital_nc_ref = CosNaming::NamingContext::_narrow(obj,ev); CosNaming::Name factory_name; factory_name.length(1); factory_name[0].id = “myFactory?; factory_name[0].kind = ““; CORBA::Object_var objref = initial_nc_ref->resolve(factory_name, ev);

   The Naming Service interface can be directly mapped to an equivalent Automation interface using the mapping rules contained in the rest of this section. A direct mapping would result in code from VisualBasic that appears as follows.

   Dim CORBA as ObjectDim ORB as ObjectDim NamingContext as ObjectDim NameSequence as ObjectDim Target as Object

   Set CORBA=GetObject(“CORBA.ORB?)Set ORB=CORBA.init(“default?)Set NamingContext = ORB.resolve_initial_reference(“NamingService?)Set NameSequence=NamingContext.create_type(“Name?)ReDim NameSequence as Object(1)NameSequence[0].name = “myFactory?NameSequence[0].kind = ““Set Target=NamingContext.resolve(NameSequence)