HOWTO: Optimize OLE Server Instance Usage by Using GetObjectLast reviewed: September 29, 1997Article ID: Q113946 |
The information in this article applies to:- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SUMMARYThis article gives a full explanation of the syntax of GetObject, adding to the information given in the "Programmer's Guide." Specifically, this article explains when a new instance of the server application is instantiated, details how to best minimize server instance usage, and gives an example that shows how to best minimize excess instances of a server application.
MORE INFORMATIONThe GetObject function has two parameters:
GetObject([pathname][,class])The pathname parameter can be the path to an existing file, "", or it can be left out. Specifying the path to an existing file causes GetObject to use an existing instance of the server application, which is either explicitly denoted in the second parameter or obtained from the registry based on the file's extension. The latter two syntax's are used to create new object references, with the added benefit over CreateObject that you can control instance usage for the server. The following table details the instance usage for the server application and gives the appropriate syntax: Server already running:
Syntax: Set X = GetObject(,"MySrvr.Object") Result: X is reference to existing object Syntax: Set X = GetObject("","MySrvr.Object") Result: X is reference to new objectServer not running:
Syntax: Set X = GetObject(,"MySrvr.Object") Result: Error 429 Syntax: Set X = GetObject("","MySrvr.Object") Result: Server is started and X references new objectTo establish a reference to an object and minimize the number of server application instances loaded, use GetObject with a blank first argument, and trap the error 429 when no instance is loaded. The following example demonstrates this. The sample application uses Microsoft Excel version 5.0 as its server application.
Steps to Create Example Program
Keywords : IAPOLE vbwin GnrlVb kbprg kbfasttip Technology : kbole kbvba Version : WINDOWS:3.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |