Home COM GDI+ WebBrowser Data Access

IMoniker Interface

 

IID_IMoniker

{0000000F-0000-0000-C000-000000000046}

 

 

The IMoniker interface contains methods that allow you to use a moniker object, which contains information that uniquely identifies a COM object. An object that has a pointer to the moniker object's IMoniker interface can locate, activate, and get access to the identified object without having any other specific information on where the object is actually located in a distributed system.

 

 

Methods in VTable order

IUnknown Methods

Description

QueryInterface

Returns pointers to supported interfaces.

AddRef

Increments reference count.

Release

Decrements reference count.

IPersist Method

Description

GetClassID

Returns the class identifier (CLSID) for the component object.

IPersistStream Methods

Description

IsDirty

Checks the object for changes since it was last saved.

Load

Initializes an object from the stream where it was previously saved.

Save

Saves an object into the specified stream and indicates whether the object should reset its dirty flag.

GetSizeMax

Return the size in bytes of the stream needed to save the object.

IMoniker Methods

Description

BindToObject

Binds to the object named by the moniker.

BindToStorage

Binds to the object's storage.

Reduce

Reduces the moniker to simplest form.

ComposeWith

Composes with another moniker.

Enum

Enumerates component monikers.

IsEqual

Compares with another moniker.

Hash

Returns a hash value.

IsRunning

Checks whether object is running.

GetTimeOfLastChange

Returns time the object was last changed.

Inverse

Returns the inverse of the moniker.

CommonPrefixWith

Finds the prefix that the moniker has in common with another moniker.

RelativePathTo

Constructs a relative moniker between the moniker and another.

GetDisplayName

Returns the display name.

ParseDisplayName

Converts a display name into a moniker.

IsSystemMoniker

Checks whether moniker is one of the system-supplied types.

 

BindToObject

 

FUNCTION IMoniker_BindToObject ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF riidResult AS GUID _

, BYREF ppvResult AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[8] USING IMoniker_BindToObject (pthis, pbc, pmkToLeft, riidResult, ppvResult) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_BindToObject ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF riidResult AS GUID _

, BYREF ppvResult AS DWORD _

  ) AS LONG

  ! push ppvResult
  ! mov  eax, riidResult
  ! push eax
  ! push pmkToLeft
  ! push pbc
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+32]
  ! mov  FUNCTION, eax

 

END FUNCTION

 

 

 

Example

 

The following function emulates the Visual Basic function GetObject.

 

' ****************************************************************************************
' Emulates the Visual Basic GetObject function
' ****************************************************************************************
FUNCTION TB_GetObjectDispatch (BYVAL strDisplayName AS STRING, BYREF vObj AS VARIANT) AS LONG

   LOCAL hr AS LONG                     ' // HRESULT
   LOCAL pbc AS DWORD                   ' // Pointer to the new bind context
   LOCAL pmk AS DWORD                   ' // IMoniker interface pointer
   LOCAL pObj AS DWORD                  ' // Interface pointer
   LOCAL pcchEaten AS DWORD             ' // Number of characters successfully parsed
   LOCAL IID_IDispatch AS GUID          ' // IDispatch inyterface identifier
   LOCAL pvObj AS VARIANTAPI PTR        ' // Pointer to a VARIANTAPI structure

   IID_IDispatch = GUID$("{00020400-0000-0000-c000-000000000046}")

   ' // Creates a new bind context.
   hr = CreateBindCtx(0, pbc)
   IF hr = %S_OK AND ISTRUE pbc THEN
      ' // Converts a string into a moniker that identifies the object named by the string.
      strDisplayName = UCODE$(strDisplayName & $NUL)
      hr = MkParseDisplayNameEx(pbc, strDisplayName, pcchEaten, pmk)
      IF hr = %S_OK AND ISTRUE pmk THEN
         ' // Uses the moniker to bind to the object it identifies.
         ' // The binding process involves finding the object, putting it into the running
         ' // state if necessary, and supplying the caller with a pointer to a specified
         ' // interface on the identified object.
         hr = IMoniker_BindToObject(pmk, pbc, %NULL, IID_IDispatch, pObj)
         IF hr = %S_OK THEN
            ' // Makes a dispatch variant containing the reference to the object.
            ' // Note: No need to call AddRef because IMoniker_BindToObject has
            ' // already called it.
            vObj = EMPTY                     ' // Make sure is empty to avoid memory leaks
            pvObj = VARPTR(vObj)             ' // Get the VARIANT address
            @pvObj.vt = %VT_DISPATCH         ' // Mark it as containing a dispatch variable
            @pvObj.vd.pdispVal = pObj        ' // Set the dispatch pointer address
         END IF
      END IF
   END IF

   IF ISTRUE pmk THEN IUnknown_Release pmk
   IF ISTRUE pbc THEN IUnknown_Release pbc

   FUNCTION = hr

END FUNCTION
' ****************************************************************************************

 

 

BindToStorage

 

FUNCTION IMoniker_BindToStorage ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF riid AS GUID _

, BYREF ppvObj AS DWORD -

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[9] USING IMoniker_BindToStorage (pthis, pbc, pmkToLeft, riid, ppvObj) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_BindToStorage ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF riid AS GUID _

, BYREF ppvObj AS DWORD -

  ) AS LONG

  ! push ppvObj
  ! mov  eax, riid

  ! push eax
  ! push pmkToLeft
  ! push pbc
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+36]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

Reduce

 

FUNCTION IMoniker_Reduce ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL dwReduceHowFar AS DWORD _

, BYREF ppmkToLeft AS DWORD _

, BYREF ppmkReduced AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[10] USING IMoniker_Reduce (pthis, pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_Reduce ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL dwReduceHowFar AS DWORD _

, BYREF ppmkToLeft AS DWORD _

, BYREF ppmkReduced AS DWORD _

  ) AS LONG
 

  ! push ppmkReduced
  ! push pmkToLeft
  ! push dwReduceHowFar
  ! push pbc
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+40]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

ComposeWith

 

FUNCTION IMoniker_ComposeWith ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkRight AS DWORD _

, BYVAL fOnlyIfNotGeneric AS LONG _

, BYREF ppmkComposite AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[11] USING IMoniker_ComposeWith (pthis, pmkRight, fOnlyIfNotGeneric, ppmkComposite) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_ComposeWith ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkRight AS DWORD _

, BYVAL fOnlyIfNotGeneric AS LONG _

, BYREF ppmkComposite AS DWORD _

  ) AS LONG

  ! push ppmkComposite
  ! push fOnlyIfNotGeneric
  ! push pmkRight
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+44]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

Enum

 

FUNCTION IMoniker_Enum ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL fForward AS LONG _

, BYREF ppenumMoniker AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[12] USING IMoniker_Enum (pthis, fForward, ppenumMoniker) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_Enum ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL fForward AS LONG _

, BYREF ppenumMoniker AS DWORD _

  ) AS LONG

  ! push ppenumMoniker
  ! push fForward
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+48]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

IsEqual

 

FUNCTION IMoniker_IsEqual ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkOtherMoniker AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[13] USING IMoniker_IsEqual (pthis, pmkOtherMoniker) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_IsEqual ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkOtherMoniker AS DWORD _

  ) AS LONG

  ! push pmkOtherMoniker
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+52]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

Hash

 

FUNCTION IMoniker_Hash ( _

  BYVAL pthis AS DWORD PTR _

, BYREF pdwHash AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[14] USING IMoniker_Hash (pthis, pdwHash) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_Hash ( _

  BYVAL pthis AS DWORD PTR _

, BYREF pdwHash AS DWORD _

  ) AS LONG

  ! push pdwHash
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+56]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

IsRunning

 

FUNCTION IMoniker_IsRunning ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYVAL pmkNewlyRunning AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[15] USING IMoniker_IsRunning (pthis, pbc, pmkToLeft, pmkNewlyRunning) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_IsRunning ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYVAL pmkNewlyRunning AS DWORD _

  ) AS LONG

  ! push pmkNewlyRunning
  ! push pmkToLeft
  ! push pbc
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+60]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

GetTimeOfLastChange

 

FUNCTION IMoniker_GetTimeOfLastChange ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF pfileTime AS FILETIME _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[16] USING IMoniker_GetTimeOfLastChange (pthis, pbc, pmkToLeft, pfileTime) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_GetTimeOfLastChange ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF pfileTime AS FILETIME _

  ) AS LONG

  ! mov  eax, pfileTime

  ! push eax
  ! push pmkToLeft
  ! push pbc
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+64]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

Inverse

 

FUNCTION IMoniker_Inverse ( _

  BYVAL pthis AS DWORD PTR _

, BYREF ppmk AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[17] USING IMoniker_Inverse (pthis, ppmk) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_Inverse ( _

  BYVAL pthis AS DWORD PTR _

, BYREF ppmk AS DWORD _

  ) AS LONG
 

  ! push ppmk
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+68]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

CommonPrefixWith

 

FUNCTION IMoniker_CommonPrefixWith ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkOther AS DWORD _

, BYREF ppmkPrefix AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[18] USING IMoniker_CommonPrefixWith (pthis, pmkOther, ppmkPrefix) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_CommonPrefixWith ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkOther AS DWORD _

, BYREF ppmkPrefix AS DWORD _

  ) AS LONG

  ! push ppmkPrefix
  ! push ppmkOther
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+72]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

RelativePathTo

 

FUNCTION IMoniker_RelativePathTo ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkOther AS DWORD _

, BYREF ppmkRelPath AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[19] USING IMoniker_RelativePathTo (pthis, pmkOther, ppmkRelPath) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_RelativePathTo ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pmkOther AS DWORD _

, BYREF ppmkRelPath AS DWORD _

  ) AS LONG

  ! push ppmkRelPath
  ! push ppmkOther
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+76]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

GetDisplayName

 

DECLARE FUNCTION Proto_IMoniker_GetDisplayName ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF ppszDisplayName AS DWORD _

  ) AS LONG
 

FUNCTION IMoniker_GetDisplayName ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYREF strDisplayName AS STRING _

) AS LONG
 

  LOCAL HRESULT AS LONG

  LOCAL ppszDisplayName AS DWORD

  LOCAL bstrlen AS LONG

  strDisplayName = ""

  CALL DWORD @@pthis[20] USING Proto_IMoniker_GetDisplayName (pthis, pbc, pmkToLeft, ppszDisplayName) TO HRESULT
  IF ISTRUE ppszDisplayName THEN
     bstrlen = lstrlenW(BYVAL ppszDisplayName)
     IF ISTRUE bstrLen THEN strDisplayName = ACODE$(PEEK$(ppszDisplayName, bstrlen * 2))
     END IF
     CoTaskMemFree ppszDisplayName
  END IF
  FUNCTION = HRESULT
 

END FUNCTION
 

 

Example

 

The following example shows the display names of all the objects currently registered in the Running Object Table (ROT)

 

#COMPILE EXE
#DIM ALL
#INCLUDE
"Win32Api.inc"
 

FUNCTION PBMAIN

   LOCAL
hr AS LONG
   LOCAL
ppbc AS DWORD
   LOCAL
pprot AS DWORD
   LOCAL
ppenumMoniker AS DWORD
   LOCAL
ppMoniker AS DWORD
   LOCAL
pceltFetched AS DWORD
   LOCAL
strDisplayName AS STRING

   ' Get a pointer to the Running Object Table (ROT)
   hr = CreateBindCtx(0, ppbc)
   IF
hr <> %S_OK OR ppbc = %NULL THEN GOTO Terminate
   hr = IBindCtx_GetRunningObjectTable(ppbc, pprot)
  
IUnknown_Release ppbc
   IF
hr <> %S_OK OR pprot = %NULL THEN GOTO Terminate
 

   ' Get a pointer to the moniker enumerator
   hr = IRunningObjectTable_EnumRunning(pprot, ppenumMoniker)
   IF
hr <> %S_OK OR ppenumMoniker = %NULL THEN GOTO Terminate

   ' Enumerate the monikers and retrieve the display name
   ppMoniker = 0
   DO
      hr = IEnumMoniker_Next(ppenumMoniker, 1, VARPTR(ppMoniker), pceltFetched)
      IF hr <> %S_OK OR ppMoniker = 0 OR pceltFetched = 0 THEN EXIT DO
      hr = IMoniker_GetDisplayName(ppMoniker, ppbc, %NULL, strDisplayName)
      IF ppMoniker THEN IUnknown_Release ppMoniker
      IF hr <> %S_OK THEN EXIT DO
      MSGBOX strDisplayName
   LOOP

   ' Release the enumerator
   IF ppenumMoniker THEN IUnknown_Release ppenumMoniker

Terminate:

   ' Release the Running Object Table
   IF pprot THEN IUnknown_Release pprot


END FUNCTION

 

 

ParseDisplayName

 

FUNCTION IMoniker_ParseDisplayName ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYVAL strDisplayName AS STRING _

, BYREF pchEaten AS LONG _

, BYREF ppmkOut AS DWORD _

) AS LONG
 

  LOCAL HRESULT AS LONG

  strDiaplayName = UCODE$(strDisplayName & $NUL)

  CALL DWORD @@pthis[21] USING IMoniker_ParseDisplayName (pthis, pbc, pmkToLeft, strDisplayName, pchEaten, ppmkOut) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_ParseDisplayName ( _

  BYVAL pthis AS DWORD PTR _

, BYVAL pbc AS DWORD _

, BYVAL pmkToLeft AS DWORD _

, BYVAL strDisplayName AS STRING _

, BYREF pchEaten AS LONG _

, BYREF ppmkOut AS DWORD _

) AS LONG
 

  LOCAL pbstrDisplayName AS STRING

  strDisplayName = UCODE$(strDisplayName & $NUL)

  pbstrDisplayName = STRPTR(dtrDisplayName)

 

  ! push ppmkOut
  ! push pchEaten
  ! lea  eax, pbstrDisplayName
  ! push eax
  ! push pmkToLeft
  ! push pbc
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+84]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

IsSystemMoniker

 

FUNCTION IMoniker_IsSystemMoniker ( _

  BYVAL pthis AS DWORD PTR _

, BYREF pdwMksys AS DWORD _

  ) AS LONG

  LOCAL HRESULT AS LONG
  CALL DWORD @@pthis[22] USING IMoniker_IsSystemMoniker (pthis, pdwMksys) TO HRESULT
  FUNCTION = HRESULT

END FUNCTION

 

 

 

FUNCTION IMoniker_IsSystemMoniker ( _

  BYVAL pthis AS DWORD PTR _

, BYREF pdwMksys AS DWORD _

  ) AS LONG

  ! push pdwMksys
  ! mov  eax, pthis
  ! push eax
  ! mov  eax, dword ptr[eax]
  ! call dword ptr[eax+88]
  ! mov  FUNCTION, eax


END FUNCTION

 

 

Page last updated on Monday, 20 March 2006 01:31:30 +0100