How Visual Basic Automation Statements Map to OLE Calls

Last reviewed: March 20, 1997
Article ID: Q122288
2.02 3.00 WINDOWS kbole kbprg kbcode kbwebcontent

The information in this article applies to:

  • Microsoft OLE Libraries for Windows and Win32s, version 2.02
  • Microsoft Visual Basic for Windows, version 3.0

SUMMARY

This article lists the OLE API and interface calls to which the Visual Basic CreateObject and GetObject calls map. Each listing shows how to obtain the IDispatch of an OLE Automation object. You can then invoke a property or method of the OLE Automation object by using IDispatch::GetIDsOfNames and IDispatch::Invoke.

MORE INFORMATION

The code listed below does not do any error checking. When you implement it, you should add the code to do necessary error checking. See the OLE SDK documentation for more information about each function or interface. Each code listing shows how to obtain the pointer to IDispatch of an Automation object in the pdisp variable.

CreateObject(progID)

This creates a new automation object and returns a pointer to the IDispatch of that object.

CLSID clsid; LPUNKNOWN punk; LPDISPATCH pdisp;

OleInitialize(NULL), if OLE isn't already loaded. CLSIDFromProgID(progID, &clsid); CoCreateInstance(clsid, NULL, CLSCTX_SERVER,

                 IID_IUnknown, (LPVOID FAR*)&punk);
punk->QueryInterface(IID_IDispatch, (LPVOID FAR*)&pdisp); punk->Release();

GetObject(filename, progID)

GetObject has three different semantics depending on the number of parameters passed. An automation object must implement IPersistFile to support GetObject(filename, progID).

CLSID clsid; LPUNKNOWN punk; LPDISPATCH pdisp; LPPERSISTFILE pPF;

OleInitialize(NULL), if OLE isn't already loaded CLSIDFromProgID(progID, &clsid); CoCreateInstance(clsid, NULL, CLSCTX_SERVER,

                 IID_IUnknown, (LPVOID FAR*)&punk);
punk->QueryInterface(IID_IPersistFile, (LPVOID FAR*)&pPF); punk->Release();

pPF->Load(filename, 0); pPF->QueryInterface(IID_IDispatch, (LPVOID FAR*)&pdisp); pPF->Release();

GetObject(filename,)

GetObject has three different semantics depending on the number of parameters passed. An automation object must implement IPersistFile to support GetObject(filename,).

LPBC pbc; ULONG cEaten; LPMONIKER pmk; LPDISPATCH pdisp;

OleInitialize(NULL), if OLE isn't already loaded CreateBindCtx(0, &pbc); MkParseDisplayName(pbc, filename, &cEaten, &pmk); BindMoniker(pmk, 0, IID_IDispatch, (LPVOID FAR*)&pdisp); pmk->Release(); pbc->Release();

GetObject(, progID)

GetObject has three different semantics depending on the number of parameters passed. An automation object must call RegisterActiveObject to support GetObject(, progID).

CLSID clsid; LPUNKNOWN punk; LPDISPATCH pdisp;

OleInitialize(NULL), if OLE isn't already loaded CLSIDFromProgID(progID, &clsid); GetActiveObject(clsid, NULL, (LPVOID FAR*)&punk); punk->QueryInterface(IID_IDispatch, (LPVOID FAR*)&pdisp); punk->Release();


Additional reference words: 2.00 3.00 VB
KBCategory: kbold kbprg kbcode kbwebcontent
KBSubcategory: LeTwoAto
Keywords : kbnetwork kbprg
Version : 2.02 3.00
Platform : WINDOWS
Resolution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 20, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.