PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: jcmatt on March 17, 2009, 03:24:27 PM

Title: DISPPARAMS problem
Post by: jcmatt on March 17, 2009, 03:24:27 PM
I put an OCX and a DLL in a project and finally got both working but the part below I just can't get.  I could sure use some help.


This is the Click code from the events file for the menu DLL:

FUNCTION MyMenuEvents1_Click(BYVAL dwCookie AS DWORD, BYREF pdispparams AS DISPPARAMS) AS DWORD
     Local pv As Variant Ptr, pvapi As VARIANTAPITYPE Ptr
      pv = pdispparams.VariantArgs : pvapi = pv
'  ==============================================================================
'  Parameters in DISPPARAMS are zero based and in reverse order
'  ==============================================================================
   STATIC Item AS LONG
      Item = VARIANT#(@pv[3])
   ...etc
END FUNCTION


I have 3 submenu items.  After clicking each:
The 1st returns: Item = 10501896
The 2nd returns: Item = 10502048
The 3rd returns: Item = 10493920

In VB6 I can get the caption by using the Item property of the Menu Click Sub with Item.Caption

How do I get the caption in PB from the Item variable shown above?


This is the setup code I'm using for the menu DLL, if it helps any:

   Object Call dispatch_form1_ocxcontrol1.MenuItems.Add(sTitle)
   Object Call dispatch_form1_ocxcontrol1.MenuItems(sTitle).subitems.Add(SubItem1)
   Object Call dispatch_form1_ocxcontrol1.MenuItems(sTitle).subitems.Add(SubItem2)
   Object Call dispatch_form1_ocxcontrol1.MenuItems(sTitle).subitems.Add(SubItem3)
   Object Let dispatch_form1_ocxcontrol1.Enabled = %True
Title: Re: DISPPARAMS problem
Post by: TechSupport on March 19, 2009, 01:32:41 PM
Hi Jim,

I just got back from a business trip since Monday... Can you let me know what OCX you are using so I can work up an example to test?
Title: Re: DISPPARAMS problem
Post by: jcmatt on March 19, 2009, 04:33:25 PM
Hi Paul,

You were missed.  Down the dll here:
http://www.jcmatt.com/Temp/Menudll.zip

Jim
Title: Re: DISPPARAMS problem
Post by: Jose Roca on March 19, 2009, 06:00:19 PM

LOCAL pMenuItem AS DWORD
LOCAL vMenuItem AS VARIANT
LOCAL oMenuItem AS DISPATCH
LOCAL vCaption AS VARIANT

pMenuItem = VARIANT#(@pv[3])
TB_MakeDispatchVariant pMenuItem, vMenuItem
SET oMenuItem = vMenuItem
IF ISOBJECT(oMenuItem) THEN
   OBJECT GET oMenuItem.Caption TO vCaption
   MSGBOX VARIANT$(vCaption)
END IF
vMenuItem = EMPTY
oMenuItem = NOTHING

Title: Re: DISPPARAMS problem
Post by: Jose Roca on March 19, 2009, 06:06:32 PM
With the new support for direct interface calls in PBWIN 9.0+, this will be much simpler:


' ########################################################################################
' Class CIwodShellMenuEvents
' Interface name = _IwodShellMenuEvents
' IID = {7E7145CE-73BE-403B-B84B-3A9413CE3647}
' _IwodShellMenuEvents Interface
' Attributes = 4096 [&H1000] [Dispatchable]
' Code generated by the TypeLib Browser 4.0.13 (c) 2008 by Jose Roca
' Date: 19 mar 2009   Time: 21:32:17
' ########################################################################################

CLASS CIwodShellMenuEvents GUID$("{036D7837-40FB-4B9D-97A6-3EF2F14E48A8}") AS EVENT

INTERFACE IwodShellMenuEventsImpl GUID$("{7E7145CE-73BE-403B-B84B-3A9413CE3647}") AS EVENT

  INHERIT IDispatch

   ' =====================================================================================
   METHOD Click <1> ( _
     BYVAL pItem AS IMenuItem _                         ' *Item IMenuItem <dispinterface>
   , BYVAL bstrName AS STRING _                         ' Name VT_BSTR
   , BYVAL Directory AS STRING _                        ' Directory VT_BSTR
   , BYVAL Targets AS STRING _                          ' Targets VT_BSTR
   )                                                    ' VOID

     ' *** Insert your code here ***
     LOCAL bstrCaption AS STRING
     bstrCaption = pItem.Caption
     MSGBOX ACODE$(strCaption)

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD BeforePopup <2> ( _
     BYVAL bstrName AS STRING _                         ' Name VT_BSTR
   , BYVAL Targets AS STRING _                          ' Targets VT_BSTR
   )                                                    ' VOID

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

   ' =====================================================================================
   METHOD AfterPopup <3>

     ' *** Insert your code here ***

   END METHOD
   ' =====================================================================================

END INTERFACE

END CLASS

Title: Re: DISPPARAMS problem
Post by: TechSupport on March 19, 2009, 06:55:01 PM
Thanks Jose !!!
Title: Re: DISPPARAMS problem
Post by: jcmatt on March 19, 2009, 07:03:09 PM
Jose,

Once again, works right out of the box.  As soon as I get a couple free years, I'm going to really get into the whole Interface thing.

Thanks much, Jim