Writing Text to an HTML Page

The following example shows how to write HTML output to a Web page from inside a server component by using the Write method exposed by the IResponse interface.

STDMETHODIMP CHowtos1::OnStartPage (IUnknown* pUnk) 
{
  HRESULT hr;  
  IScriptingContext *piContext;
  
  //Get IScriptingContext Interface
  hr = pUnk->QueryInterface(IID_IScriptingContext, (void**)&piContext);

  // Get Response Object Pointer
  IResponse* piResponse = NULL;
  hr = piContext->get_Response(&piResponse);

  //Build a String for Output
  VARIANT vtMessage;
  VariantInit(&vtMessage);
  V_VT(&vtMessage) = VT_BSTR;
  
  V_BSTR(&vtMessage) = SysAllocString(L"<CENTER><H1>Inside Component!</H1></CENTER>");

  //Write the String to the HTML Page
  piResponse->Write(vtMessage);

  VariantClear(&vtMessage);

  //Release interfaces
  piResponse->Release();
  piContext->Release();

  return S_OK;
}
 

© Microsoft Corporation. All rights reserved.