Calling a Service

After it has called QueryService to get a pointer to an interface that is part of a service, an ActiveX designer can simply call the interface through the pointer. For example, the following two lines of code get a pointer to the ICodeNavigate interface in the SCodeNavigate service (as described in the preceding section, "Finding a Service"):

hr = pClientSite->QueryInterface(IID_IServiceProvider, &pISP); 
hr = pISP->QueryService(SID_SCodeNavigate, IID_ICodeNavigate, &pICN);

Assuming that the QueryService call returns without error, the following code fragment calls the DisplayDefaultEventHandler method of ICodeNavigate:

hr = pICN->DisplayDefaultEventHandler(lpMyObject);

Typically called in response to an event such as a mouse click, this method displays the default event handler for the object named in lpMyObject.