Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

jaafar tribak

@jaafar tribak
About
Posts
9
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • EXCEL - Hooking Excel VTABLE
    J jaafar tribak

    Bump .. Any thoughts on this anyone ?

    COM design question discussion

  • EXCEL - Hooking Excel VTABLE
    J jaafar tribak

    Bump .. Any thoughts on this anyone else ?

    Visual Basic design question discussion

  • IoleUndoManager with Excel application
    J jaafar tribak

    Hi, I did ask similar questions in the VB and COM forums before and in other websites as well .. but these rather difficult questions often remain ignored or without a propper solution .. I thought VC programmers were more confortable with these type of in depth subjects. The very few vb lines in the above code snippet should be easy to understand by non vb programmers .. I hope that anyone fmiliar with ole/com would hopefully be able to give me (at least) a rough hint Regards.

    C / C++ / MFC help c++ com data-structures

  • IoleUndoManager with Excel application
    J jaafar tribak

    Hi all, First of all, I would like to apologize for posting this question in the C++ forum as it deals with Classic VB (VBA) ... The reason I posted here is because I can't get an answer (not even a hint) in the VB/VBA foums ... I searched the web extensively but without any luck I hope you guys can ,at least, point me in the right direction Problem: I am trying to control the Undo/Redo Stack in excel but I can't seem to get a pointer to the UndoManager Interface in the ppv out argument when calling the QueryService Method .. it always returns Nothing .. I hope someone can tell me what I am doing wrong .. I think the "SID_SApplicationObject" is not the right SID for what I am trying to achieve Note : I am using the olelib.tlb Code :

    Sub Test()
    Dim pUnk As olelib.IUnknown
    Dim IServiceProvider As olelib.IServiceProvider
    Dim IID_IServiceProvider As olelib.UUID
    Dim IID_IOleUndoManager As olelib.UUID
    Dim SID_SApplicationObject As olelib.UUID
    Dim ppv As IUnknown
    CLSIDFromString IIDSTR_IServiceProvider, IID_IServiceProvider
    CLSIDFromString "{0C539790-12E4-11CF-B661-00AA004CD6D8}", SID_SApplicationObject
    Set pUnk = Excel.Application
    pUnk.QueryInterface IID_IServiceProvider, IServiceProvider
    IServiceProvider.QueryService SID_SApplicationObject, IID_IOleUndoManager, ppv
    End Sub

    Any help will be much appreciated Regards.

    C / C++ / MFC help c++ com data-structures

  • IoleUndoManager with Excel application
    J jaafar tribak

    Hi all, I am trying to control the Undo/Redo Stack in excel but I can't seem to get a pointer to the UndoManager Interface in the ppv out argument when calling the QueryService Method .. it always returns Nothing .. I hope someone can tell me what I am doing wrong .. I think the "SID_SApplicationObject" is not the right SID Note : I am using the olelib.tlb Code :

    Sub Test()
    Dim pUnk As olelib.IUnknown
    Dim IServiceProvider As olelib.IServiceProvider
    Dim IID_IServiceProvider As olelib.UUID
    Dim IID_IOleUndoManager As olelib.UUID
    Dim SID_SApplicationObject As olelib.UUID
    Dim ppv As IUnknown
    CLSIDFromString IIDSTR_IServiceProvider, IID_IServiceProvider
    CLSIDFromString "{0C539790-12E4-11CF-B661-00AA004CD6D8}", SID_SApplicationObject
    Set pUnk = Excel.Application
    pUnk.QueryInterface IID_IServiceProvider, IServiceProvider
    IServiceProvider.QueryService SID_SApplicationObject, IID_IOleUndoManager, ppv
    End Sub

    Any help will be much appreciated Regards.

    COM com data-structures help

  • EXCEL - Hooking Excel VTABLE
    J jaafar tribak

    The following code is supposed to redirect the call to the Excel Calculate Method to my own function (MeMsg) After running the HookCOMFunction routine , the Test Macro successfully executes the MeMsg replacement function as expected .. So far so good However, when executing an excel calculation via the User Interface (not via code) such as by pressing the F9 key , the MeMsg replacement function doesn't get called ... I thought that replacing the 'Calculate' VTable offset address with the address of my replacement function would also work everytime excel is calculated via the User Interface Any thoughts anyone ? My goal is to hook the excel Calculate Method via code as well as via the UI Regards. Code : Option Explicit Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" ( _ Destination As Any, _ Source As Any, _ ByVal Length As Long _ ) Private Declare Function VirtualProtect Lib "kernel32.dll" ( _ ByVal lpAddress As Long, _ ByVal dwSize As Long, _ ByVal flNewProtect As Long, _ lpflOldProtect As Long _ ) As Long Private Const PAGE_EXECUTE_READWRITE As Long = &H40& Sub HookCOMFunction() Dim pVTable As Long Const lFuncOffset As Long = 84 CopyMemory pVTable, ByVal ObjPtr(Application), 4 VirtualProtect pVTable + lFuncOffset, 4&, PAGE_EXECUTE_READWRITE, 0& CopyMemory ByVal pVTable + lFuncOffset, AddressOf MeMsg, 4 End Sub Private Function MeMsg(ByVal voObjPtr As Long, ByVal Param As Long) As Long MsgBox "Excel 'Calculate Method Hooked !!" End Function Sub Test() Application.Calculate End Sub

    COM design question discussion

  • EXCEL - Hooking Excel VTABLE
    J jaafar tribak

    Yes. you are right Dave .. "DLL Redirection" is the right name and not "API hooking" such as when subclassing windows to intercept sent messages or when installing Mouse/Keyboard or CBT hooks etc The question still remains open about how to make the code I provided for overriding COM Methods work when the Methods are called via the User Interface I have searched everywhere but without any luck .. Hopefully someone knowledgeable can shed a light on this Regards.

    Visual Basic design question discussion

  • EXCEL - Hooking Excel VTABLE
    J jaafar tribak

    Hi Dave, Thanks for answering I didn't get the HookCOMFunction from anywhere .. It is my code .. Matt Curland's book "advanced Visual Basic" touches on the subject of overriding COM Methods This is similar to hooking Windows API functions which can be done with VB as well .. unfortunately, unlike when redirecting API calls , overrinding COM Methods works ONLY (at least for me) when the hooked Method is called via code and not via the User Interface Do you know if there is a section on this website about COM/interfaces ? or any other place where I can ask ? Regards.

    Visual Basic design question discussion

  • EXCEL - Hooking Excel VTABLE
    J jaafar tribak

    The following code is supposed to redirect the call to the Excel Calculate Method to my own function (MeMsg) After running the HookCOMFunction routine , the Test Macro successfully executes the MeMsg replacement function as expected .. So far so good However, when executing an excel calculation via the User Interface (not via code) such as by pressing the F9 key , the MeMsg replacement function doesn't get called ... I thought that replacing the 'Calculate' VTable offset address with the address of my replacement function would also work everytime excel is calculated via the User Interface Any thoughts anyone ? My goal is to hook the excel Calculate Method via code as well as via the UI Regards. Code : Option Explicit Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" ( _ Destination As Any, _ Source As Any, _ ByVal Length As Long _ ) Private Declare Function VirtualProtect Lib "kernel32.dll" ( _ ByVal lpAddress As Long, _ ByVal dwSize As Long, _ ByVal flNewProtect As Long, _ lpflOldProtect As Long _ ) As Long Private Const PAGE_EXECUTE_READWRITE As Long = &H40& Sub HookCOMFunction() Dim pVTable As Long Const lFuncOffset As Long = 84 CopyMemory pVTable, ByVal ObjPtr(Application), 4 VirtualProtect pVTable + lFuncOffset, 4&, PAGE_EXECUTE_READWRITE, 0& CopyMemory ByVal pVTable + lFuncOffset, AddressOf MeMsg, 4 End Sub Private Function MeMsg(ByVal voObjPtr As Long, ByVal Param As Long) As Long MsgBox "Excel 'Calculate Method Hooked !!" End Function Sub Test() Application.Calculate End Sub

    Visual Basic design question discussion
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups