Previous Page TOC Next Page



Chapter 4


Creating OLE Automation Server


by Weiying Chen


An OLE Automation server exposes automation objects that have methods and properties as their external interfaces. The methods and properties exposed by the automation objects can be directly accessed by the automation controllers such as Visual Basic or by invoking methods defined in the IDispatch interface.

In this chapter, an automation server will be created through the implementation of the IDispatch interface to illustrate the fundamental OLE automation concept. This automation server will be used in both C++ and Visual Basic.

Then, this automation server will be created through the use of MFC AppWizard (exe), Control Wizard, and the Active Template Library (ATL).

At the end of the chapter, this automation server will be used in Internet Explorer 3.0 and the HTTP Web Server.

Create and Use an Automation Server: lst41.exe


lst41.exe is an automation server implemented without using any wizards or code generation tools. This automation server exposes one method called GetMachineName. GetMachineName has no input parameter. The return value is the name of the computer where the application runs.

To expose the objects, IDispatch interface must be implemented. There are two ways to implement IDispatch interface. One way is to implement four methods in the IDispatch interface. The other way used in lst41.exe is to expose the objects through OLE automation by using the CreateStdDispatch method. CreateStdDispatch creates a standard implementation of the IDispatch interface through a single function call.

The following steps illustrates how to create lst41.exe.

  1. 1. Define the interface using Object Definition Language (ODL).
  2. Listing 4.1 highlights the lst41.odl.

Listing 4.1. lst41.odl.

  1. In Listing 4.1,the uuid attribute specifies the UUID of the item.
  2. The lcid attribute indicates that the parameter is a locale ID that provides locale information for the international string comparisons and localized member names.
  3. The helpstring attribute sets the help string associated with library or interface and so on. This information can be retrieved via the GetDocumentation function in the ITypeLib and ITypeInfo interfaces to retrieve the documentation string.
  4. The version attribute specifies a version number. Here, the version number is 1.0.
  5. The odl attribute indicates that this interface is an ODL interface.
  6. The library statement defines a type library.
  7. The importlib directive indicates that stdole32.tlb will be accessible from lst41.tlb.
  8. The interface statement defines a interface that is a set of functions. The attribute is described in a function called propget, and propput.
  9. The dispinterface statement defines a set of properties and methods that can be called by IDispatch::Invoke. Besides listing a single interface (interface Ilst41) in Listing 4.1, a dispinterface can also be defined by listing the set of methods and properties, for example,
  10. interface ILst41: IUnknown
  1. can be described as

The coclass statement defines the class ID for class name CLst41 and the interfaces supported by CLst41.

  1. 2. Create the lst41.tlb type library
  2. The type library is used by the automation clients to access the methods and properties exposed by the automation server.
  3. Lst41.tlb can be generated by executing the following command:
  1. mktyplib is a type library creation tool. It processes lst41.odl scripts and produces ilst41.h header file and a type library lst41.tlb. lst41.tlb can be read by ITypeInfo or ITypeLib interfaces.
  2. The ilst41.h header file is shown in Listing 4.2.

Listing 4.2. C++ header file: ilst41.h

  1. From Listing 4.2,
  1. has been expanded into seven methods, three IUnknown methods and four IDispatch methods, which include GetTypeInfoCount, GetTypeInfo, GetIDsOfNames, and Invoke.
  2. Method GetTypeInfoCount retrieves the number of type information interfaces provided by an object. If the object provides the type information, pctinfo will be 1, otherwise it will be 0.
  3. GetTypeInfo method retrieves a type-information object. This object can be used to get the type information for an interface.
  4. GetIDsOfNames method retrieves a DISPID corresponding to the methods and arguments provided.
  5. Invoke method accesses the properties and methods given their DISPID.
  6. 3. Implement the ILst41 interface. (See Listing 4.3.)

Listing 4.3. ILst41 implementation.
Clst41I and CLst41 class definition

Clst41I and CLst41 class implementation
  1. Function CreateBSTR will convert an ASCII string to a wide character (Unicode) string. In particular, function MultiByteToWideChar will convert an ASCII string pointed by lpString to a wide character string pointed by bsz. CP_ACP specifies the code page to be used by the conversion. It stands for ANSI code page. Other code page includes CP_MACCP that indicates a Macintosh code page, and CP_OEMCP that indicates an OEM code page.
  1. Function CreateDispatchInterface will first use registry information to load the type library by invoking the LoadRegTypeLib function. There are four parameters. LIBID_Lst41 is the Library ID being loaded. 1 is the type library (lst41.tlb)'s major version number. 0 is the lst41.tlb's minor version number. 0x0409 is the U.S English, which is the library's national language code. ptlib is a indirect pointer to ITypeLib interface.
  2. If the type library information cannot be loaded from the registry, LoadTypeLib function will be called. LoadTypeLib loads and registers the type library stored in lst41.tlb.
  3. GetTypeInfoOfGuid will retrieve IID_ILst41's type description, and return ptinfo, which is a indirect pointer to ITypeInfo.
  4. After successfully invoking GetTypeInfoOfGuid, the CreateStdDispatch function will be invoked. This function creates a standard implementation of the IDispatch interface through one single function call. There are four parameters in this function. punkController is a pointer to the ILst41 IUnknown implementation. pProgInterface is a pointer to the object to expose. ptinfo is a pointer to the ILst41's type information that describes the exposed object. punkStdDisp is an indirect pointer to the ILst41 IDispatch interface implementation.
CLst41::CLst41() CLst41::~CLst41()
  1. QueryInterface will check the interface identifier riid. If riid is equal to IID_IUnknown, this value will be assigned to *ppv because CLst41 is the controlling IUnknown. If riid is equal to IID_IDispatch or DIID_DLst41 or IID_ILst41, *ppv will be the standard dispatch interface. Otherwise, *ppv will be NULL and the error code E_NOINTERFACE will be returned.
  1. PostQuitMessage function will indicate to the system that the thread will be terminated by posting a WM_QUIT message to the thread's message queue and return. When the thread receives the WM_QUIT from the message queue, it will terminate the message loop and return the control to the window.
  2. 4. Implement the Class Object for CLst41.
  3. Listing 4.4 demonstrates the CLst41 class factory implementation.

Listing 4.4. CLst41 class factory.

  1. 5. Create the main entry.
  2. An Automation server can be one of two types. One is DLL based and can be driven only by automation clients. The other is .EXE based and can run standalone.
  3. Lst41.exe is an .EXE-based automation server. To create a .EXE-based automation server, you must provide a main entry. Listing 4.5 demonstrates how to implement the main entry.

Listing 4.5. Main entry for Lst41.exe.

  1. In Listing 4.5, first OleInitialize is invoked to initialize the OLE library. This function must be called before calling any OLE functions. Then CLst41::Create is invoked to create a single global instance of CLst41. CLst41CF::Create is called to create an instance of the class factory for CLst41. Register the class factory by invoking CoRegisterClassObject. Then the message loop is provided. When the WM_QUIT message is received, the message loop will be terminated. CoRevokeClassFactory will be called to inform OLE that the object is no longer available if the class factory was successfully created earlier. Finally, OleUninitialize will be called to uninitialize the OLE library and release all the resources.
  2. 6. Create the registration entry.
  3. lst41.exe has to be registered before being used. Listing 4.6 shows the registration file for lst41.exe.

Listing 4.6. lst41.reg file

  1. In Listing 4.6, Lst41.Application.1 is the ProgID, which is required for any automation objects. It is used by an automation controller to reference an automation server. LocalServer32 subkey specifies the full path to the 32-bit automation server lst41.exe.

Use Lst41 in C++ Application: lst41use.exe


lst41use.exe is a C++ application that uses lst41.exe. It uses IDispatch to access exposed objects.

Listing 4.7 demonstrates how to use IDispatch to access the methods exposed by lst41.exe.

Listing 4.7. lst41use.cpp


#include <objbase.h>

#include <initguid.h>

#include <stdio.h>

DEFINE_GUID(CLSID_CLst41,0x9FBBEDE5L,0x1B40,0x11D0,0x88,0xE0,

0x00,0xAA,0x00,0x4A,0x7C,0x7B);

LPSTR BstrToSz(LPCOLESTR pszW)

{

    ULONG cbAnsi, cCharacters;

    DWORD dwError;

    LPSTR lpString;

    if(pszW == NULL)

        return NULL;

    cCharacters = wcslen(pszW) + 1;

    cbAnsi = cCharacters * 2;

    lpString = (LPSTR) CoTaskMemAlloc(cbAnsi);

    if(NULL == lpString)

        return NULL;

    if(WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, lpString,

                           cbAnsi, NULL, NULL) == 0)

    {

        dwError = GetLastError();

        CoTaskMemFree(lpString);

        lpString = NULL;

    }

    return lpString;

}

Function BstrToSz converts a wide-character (Unicode) string to an ASCII string. CoTaskMemAlloc allocates a memory block using the default allocator. It behaves the same way as IMalloc::Alloc. The application should always check the return value from this function. Function WideCharToMultiByte maps a wide character string pointed by pszW to an ASCII string pointed by lpString.


void main()

{

    HRESULT hr;

    IDispatch *pIDispatch;

    DISPPARAMS dispparms = {NULL, NULL, 0,0};

    DISPID dispidGetMachineName;

    OLECHAR *pGetMachineName = L"GetMachineName";

    IUnknown *pIUnknown;

    VARIANT varResult;

    hr = OleInitialize(NULL);

    hr = CoCreateInstance(CLSID_CLst41, 0, CLSCTX_SERVER, IID_IUnknown,

                         (void**)&pIUnknown);

    if(FAILED(hr))

        printf("the error is %x\n", hr);

    pIUnknown->QueryInterface(IID_IDispatch, (void**)&pIDispatch);

    pIUnknown->Release();

    pIDispatch->GetIDsOfNames(IID_NULL,

                            &pGetMachineName,

                            1, LOCALE_SYSTEM_DEFAULT, &dispidGetMachineName);

    pIDispatch->Invoke(dispidGetMachineName, IID_NULL, LOCALE_SYSTEM_DEFAULT,

                       DISPATCH_METHOD, &dispparms,

                    &varResult, NULL, NULL);

    printf("the striing is %s\n", BstrToSz(varResult.bstrVal));

    pIDispatch->Release();

    CoUninitialize();

}

Function CoCreateInstance creates an CLst41 object. Because lst41.exe is a local server, execution context CLSCTX_SERVER is used. CLSCTX_SERVER is defined as


#define CLSCTX_SERVER (CLSCTX_INPROC_SERVER| CLSCTX_LOCAL_SERVER| CLSCTX_REMOTE_SERVER)

GetIDsOfNames retrieves the DISPID and will be stored in dispidGetMachineName. There are five parameters in GetIDsOfNames. IID_NULL must be NULL; it is reserved for future use. pGetMachineName points to the method name. 1 indicates there is only one name to be mapped. LOCALE_SYSTEM_DEFAULT indicates the locale context in which to interpret the name.

Invoke accesses the GetMachineName method by providing its DISPID varResult is used to hold the return value from GetMachineName method.

Use lst41 in Visual Basic Application


With Visual Basic, using lst41.exe is straightforward. Listing 4.8 demonstrates how to use lst41.exe.

Listing 4.8. lst41.exe used in Visual Basic.


Dim x As Object

Dim strMachineName As String

Set x = CreateObject("lst41.application.1")

strMachineName = x.getmachinename

MsgBox strMachineName

In Listing 4.8, variable x is declared as an object and assigned the return of CreateObject call. The parameter in the CreateObject call is the ProgID of lst41.exe.

After the automation server (lst41.exe) is instantiated, the method GetMachineName can be invoked; the return value is assigned to strMachineName.

To try the example, place a CommandButton control on a form, and type Listing 4.8 into the command button's click proc. Run the example and click the Command1 button. A dialog box with the computer name on which the application is running will be displayed.

Create lst41 by Using the MFC ClassWizard (exe): lst42.exe


There are two MFC ClassWizard option provided by the New Project Workspace as shown in Figure 4.1.

Figure 4.1. New Project Workspace.

MFC AppWizard is designed to configure the skeleton of a new C++ application using the MFC.

MFC AppWizard (exe) is designed to create MFC extension .EXE, whereas MFC AppWizard (dll) is designed to create an MFC extension .DLL. The following steps illustrate how to create lst42.exe.

  1. 1. Choose File|New. In the New dialog box, select the file type "Project Workspace."
  2. 2. In the New Project Workspace dialog box, choose the MFC AppWizard (exe) in the type box. Type lst42 in the Name edit box and click the Create... button shown in Figure 4.2.

Figure 4.2. New Project Workspace dialog box.

  1. 3. Choose the Single document option shown in Figure 4.3.
Note


The single-document option allows the application to work with one document at a time



The multiple-document option allows the application to work with multiple documents, each document with its own view.

Figure 4.3. MFC AppWizard—Step 1.

  1. 4. Choose the Mini-server option and the OLE automation as shown in Figure 4.4.

Figure 4.4. MFC AppWizardmdStep 3 of 6.

Note


The Mini-server option allows the application to create and manage the compound document object. Mini-server cannot run standalone, and only supports embedded objects, whereas Full-server can run standalone and supports both linked and embedded objects.



The OLE automation option allows the application to be accessed by the automation clients, such as Visual Basic, Access, Excel.

  1. 5. Click the Finish button. The files listed in Figure 4.5 will be generated by the MFC AppWizard (exe). Click the OK button to generate all the files.

Figure 4.5. New Project Information.

  1. Among the files listed in Figure 4.5, the following classes and source files are specific to OLE:
  2. SrvrItem.h, SrvrItem.cpp: This is the class that connects CLst42Doc to the OLE system. It also optionally provides links to the document.
  3. IpFrame.h, lpFrame.cpp: This class is derived from COleIPFrameWnd and controls all frame features during in-place activation.
  4. lst42.reg: This is a .REG file. This file can be used to manually register the application.
  5. lst42.odl: This is the .ODL file, which is read by MkTypLib to create a type library (.TLB). A Type library is used by automation clients to retrieve information about the server's properties and its data types, methods, and its return value and parameters. Listing 4.9 shows the lst42.odl file.

Listing 4.9. Lst42.odl.

  1. ODL consists of attributes, statements, and directives.
  1. is the attribute, which associates information with the library. The uuid is for the type library. All applications that expose type information must register the information to the system registry so that it is available to type browsers or any automation clients.
  2. The definition on the library Lst42 is enclosed between { and }. In the definition. import indicates that lst42.tlb imports the standard OLE library stdole32.tlb. dispinterface defines a set of methods and properties that can be invoked by IDispatch::Invoke. coclass named Document indicates that supported interface ILst42 in this component object (lst42.exe). A GUID must be given on a coclass. This GUID is the same as CLSID registered in the system.
  3. 6. From the View menu, choose the ClassWizard command, select the OLE Automation tab, and choose CLst42Doc in the Class name dropdown list box shown in Figure 4.6.

Figure 4.6. MFC ClassWizard—OLE Automation.

  1. 7. Click the Add Method... button in Figure 4.6. Type GetMachineName in the External name dropdown combo box, select BSTR in the Return type dropdown list box, and click OK button in the Add Method dialog box displayed in Figure 4.7.

Figure 4.7. Add Method dialog box.

Note


External name is used by the automation clients to invoke the exposed method, whereas Internal name is the member function that implements the exposed method.

  1. 8. Modify the class lst42Doc.cpp. Add the code shown in Listing 4.10.

Listing 4.10. Method implementation.

  1. Lst42.exe only has one exposed method, GetMachineName. Listing 4.11 demonstrates the dispatch map generated by the MFC AppWizard (exe).

Listing 4.11. Dispatch map for lst42.exe.

  1. Listing 4.11 is abridged from lst42Doc.cpp to emphasize the essential parts. DISP_FUNCTION macro is used in the dispatch map to define an exposed method. The dispatch map is a mechanism provided by MFC to dispatch the request made by the automation clients, such as calling the methods and accessing the properties.
  2. The Dispatch map indicates the external and internal name of the properties and methods, as well as the properties' data types and method's argument and return type.
  3. In Listing 4.11, CLst42Doc is the name of the class. COleServerDoc is the base class. DISP_FUNCTION macro is used to define an automation method. GetMachineName is the external name used by the automation clients, GetMachineName is the internal name, VT_BSTR is the return type, VTS_NONE is the method's parameter list. In this case, there is no input parameter.
  4. Besides the DISP_FUNCTION macro defined in the dispatch map, other macros are provided as shown in the following list:
  5. DISP_PROPERTY defines an automation property.
  6. DISP_PROPERTY_EX defines an automation property and names the "get" and "set" functions.
  7. DISP_PROPERTY_NOTIFY defines an automation property with notification.
  8. DISP_PROPERTY_PARAM defines an automation property, names the "get" and "set" functions, and an index parameter.
  9. DECLARE_DISPATCH_MAP is used in the class declaration to indicate that a dispatch map will be used.
  10. For example,
  1. is used in the lst42Doc.h to indicate that a dispatch map will be used in CLst42Doc class.
  1. 9. Build the project to generate lst42.exe.
  2. Before lst42.exe can be used by the automation clients or any other information, lst42.exe must be registered with the system. This can be done by running one of the following commands:
  3. regedit /s lst42.reg
  4. lst42.exe /regserver
Note


Automation server generated by the MFC AppWizard (exe) provides the self registration features. In other words, lst42.exe accepts the program argument /regserver to register itself to the system registry.

After lst42.exe is registered with the system, it can be used by automation clients, such as Visual Basic, Access, Excel. lst42.exe can be accessed by using IDispatch interface in the C++ application.

The following example demonstrates how lst42.exe be used in Visual Basic 4.0.

With Visual Basic, using lst42.exe is straightforward. Listing 4.12 demonstrates how to use lst42.exe inside Visual Basic.

Listing 4.12. lst42.exe used in Visual Basic.


Dim x As Object

Dim strMachineName As String

Set x = CreateObject("lst42.document")

strMachineName = x.getmachinename

MsgBox strMachineName

In Listing 4.12, variable x is declared as an object and assigned the return of the CreateObject call. The parameter in the CreateObject call is the ProgID of lst42.exe. For any application generated by the MFC AppWizard with OLE automation enabled, the ProgID is always Name for the new project workspace plus the .document.

After the automation server (lst42.exe) is instantiated, the method GetMachineName can be invoked and the return value is assigned to strMachineName.

To try the example, place a CommandButton control on a form and type Listing 4.13 into the command button's click proc. Run the example and click the Command1 button. A dialog box with the name of the computer the application is running on will be displayed.

Create lst41 by Using the Control Wizard: lst43.ocx


Besides using MFC AppWizard (exe) to create the automation server, Control Wizard can be used. The IsInvokeAllowed() method is required to be overriden to support the automation.

The following steps demonstrates how to implement an automation server supporting the same functionality as lst41.exe.

  1. 1. Choose File|New. In the New dialog box, select the file type "Project Workspace."
  2. 2. In the New Project Workspace dialog box, choose the OLE ControlWizard. Type lst43 in the Name edit box and click the Create… button shown in Figure 4.8.

Figure 4.8 New Project Workspace—OLE Control Wizard

  1. 3. Click the Finish button. Files shown in Figure 4.9 will be generated. Click the OK button in the dialog box displayed in Figure 4.9.

Figure 4.9. Files generated by OLE ControlWizard.

Among the files shown in Figure 4.9, the following files are specifically related to the Control.

lst43Ctl.bmp: containing a bitmap displayed in the container's toolbox, such as Visual Basic's toolbox.

  1. 4. Choose View|ClassWizard. Select the OLE Automation tab shown in Figure 4.10, click the Add Method… button, enter GetMachineName, and choose BSTR as the return type in the Add Method dialog box displayed in Figure 4.11.

Figure 4.10. OLE Automation tab in MFC ClassWizard.

Figure 4.11. Add Method in OLE Automation tab.

  1. 5. Implement the GetMachineName method by modifying lst43Ctl.cpp.
  1. 6. Override IsInvokeAllowed.
  2. Add the following declaration in class CLst43Ctrl in lst43Ctl.h.
  1. Add the IsInvokeAllowed implementation in lst43Ctl.cpp.
  1. 7. Build the application to generate lst43.ocx.
  2. lst43.ocx can be used in the Visual Basic the same way as lst42.exe. Instead of Listing 4.12, code in Listing 4.13 should be entered.

Listing 4.13. lst43.ocx used in Visual Basic.

  1. Lst43.ocx supports self registration. To register lst43.ocx, run regsvr32 lst43.ocx, to unregister lst43.ocx, run regsvr32 /u lst43.ocx.
  2. In Listing 4.13, ProgID for lst43.ocx is lst43.lst43ctrl.1. The default ProgID generated by OLE ControlWizard is always the name for the new project workspace plus .lst43ctrl.1.
  3. There is one method exposed by lst43.ocx. Listing 4.14 is the dispatch map generated by the ClassWizard.

Listing 4.14. Dispatch map for lst43.ocx.

  1. In Listing 4.14, DISP_FUNCTION is exactly the same as in Listing 4.12, except the class name is CLst43Ctrl instead of CLst42Doc.

Create lst41 by Using the Active Template Library: lst44.dll


ATL provides an OLE COM AppWizard to create COM objects. It supports COM objects with a custom interface, IDispatch, and IConnectionPoint and so on. ATL is designed to create COM objects. For more information on ATL, please refer to Appendix E, "ActiveX Template Library."

The following example illustrates how to use ATL to create an automation server supporting the same functionality as lst41.exe.

  1. 1. Choose File|New. In the New dialog box, select "Project Workspace" in the type box.
  2. 2. In the New Project Workspace dialog box, choose the OLE COM AppWizard. Type lst44 in the Name edit box and click the Create… button shown in Figure 4.12.

Figure 4.12. OLE COM AppWizard.

  1. 3. Use the default option displayed in Figure 4.13.

Figure 4.13. OLE COM AppWizard—Step 1 of 2.

Note


The Dual Interface option indicates that the interface supports IDispatch and IUnknown.

  1. The Custom Interface option indicates the interface only supports IUnknown.

  1. 4. Implement the GetMachineName method
  2. Add the following code in bold font to interface ILst44 definition in lst44.idl.
  1. Add the following code in bold font to interface ILst44 definition in lst44.odl.
  1. Add the following code in CLst44Object.h in lst44obj.h.
  1. Add GetMachineName implementation in lst44obj.cpp shown in Listing 4.15.

Listing 4.15. Addition to lst44obj.cpp.

  1. In Listing 4.15, function CreateBSTR accepts an ASCII string, and converts into a Unicode string. Unicode stands for a 16-bit character set that can encode all known character sets and is used as a world-wide character encoding standard.
  2. 5. Before building the project, using the midl lst44.idl command to generate a source file for a custom OLE interface.
  3. 6. Build the project to generate lst44.dll.

lst44.dll can be used in Visual Basic the same way as lst42.exe. Instead of input Listing 4.11, code in Listing 4.16 should be entered.

Listing 4.16. Lst44.dll used in Visual Basic.


Dim x As Object

Dim strMachineName As String

Set x = CreateObject("lst44.lst44object.1")

strMachineName = x.getmachinename

MsgBox strMachineName

Before running the preceding code, lst44.dll needs to be registered by running regsvr32 lst44.dll.

In Listing 4.16, ProgID for lst44.dll is lst44.lst44object.1. The default ProgID generated by OLE COM AppWizard is the name of the project workspace plus .lst44object.1.

The default ProgID can be modified by replacing the code in bold font as shown in the following; this code is contained in lst44.cpp.


BEGIN_OBJECT_MAP(ObjectMap)

    OBJECT_ENTRY(CLSID_Lst44, CLst44Object, "LST44.Lst44Object.1",

    "LST44.Lst44Object.1", IDS_LST44_DESC, THREADFLAGS_BOTH)

END_OBJECT_MAP()

Use lst44.dll on the Internet Explorer 3.0 and Web Server


Reusable components such as automation server not only can be used in the automation clients such as Visual Basic, Access, Excel, or in the application that accesses the automation server via IDispatch. Microsoft Internet Explorer (IE) 3.0 also supports the use of automation server.

The automation server inside IE 3.0 requires an <OBJECT> tag to be used to include the object.

Listing 4.17 demonstrates how to use lst44.dll inside an HTML page and displayed in IE 3.0 browser.

Listing 4.17. lst44.dll used in IE 3.0.


<HTML>

<HEAD>

<OBJECT  classid="clsid:C566CC25-182E-11D0-A6AD-00AA00602553"

    id= MachineName

</OBJECT>

<SCRIPT language="VBScript">

    msgbox MachineName.getmachinename

</SCRIPT>

</HEAD>

</HTML>

In Listing 4.17, "clsid:..." is the string representation of the CLSID, denoted as {CLSID}, for lst44.dll. The following steps illustrates how to get the {CLSID} for lst44.dll.

  1. 1. Run regedt32
  2. 2. Go to HKEY_CLASSES_ROOT and then find lst44.lst44object.1 subkey in HKEY_CLASSES_ROOT.
  3. 3. Get the value of the CLSID subkey under lst44.lst44object.1, shown in Figure 4.14.

Figure 4.14. ProgID and {CLSID} registry key for lst44.dll.

  1. 4. Double-click the data, and a string editor dialog box will be displayed shown in figure 4.15.

Figure 4.15. String Editor for data.

  1. 5. Paste the value in string editor to the HTML page.
  2. When IE 3.0 browses this page, a message box will pop up, showing the computer name.
  3. Automation server can be used not only on the browser's side, but also on the Web server side.
  4. To use the automation server on the Web server side, Internet Personalization System (IPS) needs to be installed on top of the Internet Information Server (IIS). IPS provides the environment to support the usage of automation servers. It also provides the intrinsic controls listed as follows:
  5. The Request component is composed of three items within a collection: ServerVariables, QueryString, and Body. The collection can be accessed via
  1. The collection name is optional; if it is not provided, the server will search the collection in the following order:
  1. The ServerVariables collection supports all HTTP headers by prefixing them with HTTP_ and the variables including AUTH_TYPE, CONTENT_LENGTH, CONTENT_TYPE, GATEWAY_INTERFACE, PATH_INFO, PATH_TRANSLATED, QUERY_STRING, REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, REMOTE_USER, REQUEST_METHOD, SCRIPT_NAME, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, and SERVER_SOFTWARE.
  2. The HTTP headers can be found at http://www.w3.org.
  3. The QueryString collection provides access to all parameters in the Get method.
  4. The Body collection provides access to all parameters in the Post method
  5. The Response components exposes methods or properties including Add(header-value, header-name), AppendToLog(string), Clear, Expires, Redirect(url), SetCookie(name, value[expires, [domain,[path,[secure,]]]]), and Status.
  6. The Server components exposes three methods: HTMLEncode (string), Include(filename), and MapPath(vitual path).
  7. Listing 4.18 demonstrates how to use lst44.dll on the Web server side so that the user can get the Web server machine name.

Listing 4.18. Use lst44.dll on Web server.
getmachinename.asp file

  1. In Listing 4.18, .asp stands for active server page. It is designated script files. The extension .asp will cause the Web server to invoke the IPS script interpreter. <% ... %> indicates that scripting language expressions, <% = %> indicates that the value of the expression will put into the HTML stream.
  2. In Listing 4.18, getmachinename.asp should be placed under the scripts directory, and machinename.html placed under the wwwroot directory. When machinename.html page is launched and link "Get the Server Machine Name" is clicked, the Web server machine name will be displayed in the browser.

Summary


An OLE automation server is a COM server with the support of the IDispatch interface. Applications can use IDispatch to access exposed objects in automation server. A lot of tools can be used to develop the automation servers by using MFC AppWizard, Control Wizard, and Active Template Library. The automation server is a reusable component, which can be used in the automation controller, IE 3.0, and Web server.

Previous Page Page Top TOC Next Page