GETINTERFACE( ) Function

Provides access to COM object properties, methods, and events through early binding.

GETINTERFACE(oObject [, cIID | cInterface[, cTypelib | cProgID]])

Parameters

  • oObject
    Specifies the target COM object.
  • cIID
    Specifies the GUID of the target interface of oObject. cIID can be an interface such as "IContextState" or it can be a GUID, such as "{94631BEC-EE81-479A-AE64-A6CFC37B4799}". If it's "IDispatch", then GetInterface() returns an IDispatch (late-bound) reference to the object. If cIID is not specified, then GetInterface() will return the early binding interface for the object.
  • cInterface
    Specifies the interface name.
  • cTypelib
    Specifies the name of the type library containing the oObject class.
  • cProgID
    Specifies the name of the program to be used to lookup the type library.

Returns

COM Object Interface reference

Remarks

GetInterface( ) applies only to COM objects. If you use native Visual FoxPro objects, GetInterface( ) generates an error. GetInterface( ) returns an early-bound Object reference.

When a DLL is built on a Windows 95, Windows 98, or Windows Me platform, Visual FoxPro does not include the type library inside the DLL. When you use GETINTERFACE( ) and refer to a DLL built on one of these platforms, you must use the Type Library name instead of the DLL name as in the following code:

oX = GETINTERFACE(x, "Imyclass", "myclass1.TLB")

You can use the following code for a DLL built on Windows XP, Windows 2000, or Windows NT:

oX = GETINTERFACE(x, "Imyclass", "myclass1.DLL")

Example

The following code example provides a method you can use in your Visual FoxPro COM server to handle transactions in a COM+ application. This sample requires that you add the COM server containing this code to a COM+ application before a client calls it.

LOCAL oMTX, oContext, oContextState
LOCAL lTxnState, lGetTxnState, lDone, lGetDone
lGetDone = .F.     && initialize setting
lGetTxnState = 0  && initialize setting

oMTX = CREATEOBJECT("MTXAS.APPSERVER.1")
oContext = oMTX.GetObjectContext()
oContextState = GetInterface(oContext,"IContextState")

* Handle activation setting (Doneness)
* Values: .T. - Deactivate, .F. - Leave activated
lDone = .T.
oContextState.SetDeactivateOnReturn(lDone)
oContextState.GetDeactivateOnReturn(@lGetDone)
     
* Handle transaction setting (Consistency)
* Values: 0 - commit, 1 - abort
lTxnState = 1
oContextState.SetMyTransactionVote(lTxnState)
oContextState.GetMyTransactionVote(@lGetTxnState)

See Also

Tasks

How to: View Type Library Information

Reference

CREATEOBJECTEX( ) Function
Early (vtable) and Late (IDispatch) Binding
GETOBJECT( ) Function
SYS(2333) - ActiveX Dual Interface Support

Other Resources

Functions
Language Reference (Visual FoxPro)