Results 1 to 21 of 21

Thread: CoGetObject API -- Initialize and get a pointer to the Office IRibbonUI Interface ?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Exclamation CoGetObject API -- Initialize and get a pointer to the Office IRibbonUI Interface ?

    Hi all,

    I am trying to get a pointer to the OFFICE IRibbonUI Interface using the CoGetObject API in the code below but the last OUT argument (ByRef ppv As Any) of the CoGetObject function returns an UnKnown type or an Object type instead of IRibbonUI type .

    Can anyone shed a light on this ?

    Thank you.

    Code:
    Option Explicit
    
    Private Type GUID
        data1    As Long
        data2    As Integer
        data3    As Integer
        data4(7) As Byte
    End Type
     
    Private Declare Function IIDFromString Lib "Ole32" ( _
    ByVal lpszIID As Long, _
    iid As Any) As Long
    
    Private Declare _
    Function CoGetObject Lib "Ole32" ( _
            ByVal pszName As Long, _
            ByVal pBindOptions As Long, _
            ByRef riid As GUID, _
            ByRef ppv As Any) As Long
     
    
    Sub Test()
    
        Dim iRibbon As IUnknown  ' As Object
        Dim iid     As GUID
        Dim hRes As Long
        
        Const IID_UNKNOWN As String = "{00000000-0000-0000-C000-000000000046}" 'Iunknown Interface GUID.
        
        'get the iunknown interface
        hRes = IIDFromString(StrPtr(IID_UNKNOWN), iid)
        
        'get pointer to the iRibbonUI interface
        '"{926749fa-2615-4987-8845-c33e65f2b957}" = UIRibbonFramework ClassID
        hRes = CoGetObject(StrPtr("new:926749fa-2615-4987-8845-c33e65f2b957"), 0, iid, iRibbon)
        
        MsgBox TypeName(iRibbon) '<=== Should return IRibbonUI but returns UnKnown
    
    End Sub
    Last edited by JAAFAR; Jul 18th, 2018 at 02:31 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width