Bump .. Any thoughts on this anyone ?
jaafar tribak
Posts
-
EXCEL - Hooking Excel VTABLE -
EXCEL - Hooking Excel VTABLEBump .. Any thoughts on this anyone else ?
-
IoleUndoManager with Excel applicationHi, 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.
-
IoleUndoManager with Excel applicationHi 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 SubAny help will be much appreciated Regards.
-
IoleUndoManager with Excel applicationHi 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 SubAny help will be much appreciated Regards.
-
EXCEL - Hooking Excel VTABLEThe 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
-
EXCEL - Hooking Excel VTABLEYes. 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.
-
EXCEL - Hooking Excel VTABLEHi 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.
-
EXCEL - Hooking Excel VTABLEThe 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