• Welcome to Theos PowerBasic Museum 2017.

IClassFactory Built In Interface

Started by Frederick J. Harris, August 27, 2010, 09:51:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frederick J. Harris

I just noticed at the end of the "Objects and COM Programming" section of the PowerBASIC Help manual there is a final topic named "Built In Interfaces".  I either never noticed that before, or maybe its relatively new.  Anyway, I was startled when I saw it.  I notice that ICLASSFACTORY is one of the several listed.  I always knew that was built in, because I've always had to create my own for my low level COM programming endeavors and attach a '1' or something like that at the end.  I always did that because I figured PowerBASIC's ICLASSFACTORY was proprietary and I shouldn't mess with it.  Just out of curiousity I stuck this in na working program...


Local pClassFactory As IClassFactory
Local pIX As I_X   'one of the interfaces from my tutorials
Let pIX = AnyCom "ComObject.cc"
pClassFactory = pIX


...and it compiled fine!

That amazed me.  Is there a way to use PowerBASIC's built in ICLASSFACTORY?  Obtain a pointer to it?

José Roca

 
Of course. In Unknown.inc you can find the following:


' ########################################################################################
' IClassFactory interface
' IID = 00000001-0000-0000-C000-000000000046
' Inherited interface = IUnknown
' NOTE: Renamed because of conflicts with the built-in PB definition.
' ########################################################################################

#IF NOT %DEF(%IClassFactory_INTERFACE_DEFINED)
   %IClassFactory_INTERFACE_DEFINED = 1

$IID_IClassFactory = GUID$("{00000001-0000-0000-C000-000000000046}")

INTERFACE COM_IClassFactory $IID_IClassFactory

  INHERIT IUnknown

  ' =====================================================================================
  METHOD CreateInstance ( _                            ' VTable offset = 12
    BYVAL pUnkOuter AS IUnknown _                      ' __in IUnknown *pUnkOuter
  , BYREF riid AS GUID _                               ' __in REFIID riid
  , BYREF ppvObject AS IUnknown _                      ' __out void **ppvObject
  ) AS LONG                                            ' HRESULT
  ' =====================================================================================
  METHOD LockServer ( _                                ' VTable offset = 16
    BYVAL fLock AS LONG _                              ' __in BOOL fLock
  ) AS LONG                                            ' HRESULT
  ' =====================================================================================

END INTERFACE

#ENDIF   ' /* __IClassFactory_INTERFACE_DEFINED__ */

' *** As built into the PowerBASIC compiler ***

'INTERFACE IClassFactory $IID_IClassFactory

'   INHERIT IUnknown

'   ' =====================================================================================
'   METHOD CreateInstance ( _                            ' VTable offset = 12
'     BYVAL pUnkOuter AS DWORD _                         ' __in IUnknown *pUnkOuter
'   , BYREF riid AS GUID _                               ' __in REFIID riid
'   , BYVAL ppvObject AS DWORD PTR _                     ' __out void **ppvObject
'   ) AS LONG                                            ' HRESULT
'   ' =====================================================================================
'   METHOD LockServer ( _                                ' VTable offset = 16
'     BYVAL fLock AS LONG _                              ' __in BOOL fLock
'   ) AS LONG                                            ' HRESULT
'   ' =====================================================================================

'END INTERFACE


Notice that the only difference is that, in the built-in interface definition, the ppvObject is declared as BYVAL DWORD PTR instead of BYREF IUnknown.