-2147467259 = 0x80004005 = E_FAIL = Unspecified failure (
src)
Code: Select all
To obtain an IDispatch interface pointer to a class supported by the native object model, specify OBJID_NATIVEOM in dwObjectID. When using this object identifier, the hwnd parameter must match the following window class types.
Office application Window class IDispatch pointer to
Word _WwG Window
Excel EXCEL7 Window
PowerPoint paneClassDC DocumentWindow
Command Bars MsoCommandBar CommandBar
(
src)
-changed to use "paneClassDC"
-added some code to translate the hr value into a more readable name
-added Return Type to AccessibleObjectFromWindow dllcall
Code: Select all
; Ppt_Get.ahk: burque505, modified from
; Excel_Get by jethrow (modified)
; Forum: https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
; Github: https://github.com/ahkon/MS-Office-COM-Basics/blob/master/Examples/Excel/Excel_Get.ahk
; With subsequent mods by opiuetasfd - thanks!
Ppt_Get(WinTitle:="ahk_class PPTFrameClass", paneClassDC#:=1) {
static h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
static hrVal := { 0x00000000: "S_OK", 0x80004004: "E_ABORT", 0x80070005: "E_ACCESSDENIED", 0x80004005: "E_FAIL"
, 0x80070006: "E_HANDLE", 0x80070057: "E_INVALIDARG", 0x80004002: "E_NOINTERFACE", 0x80004001: "E_NOTIMPL"
, 0x8007000E: "E_OUTOFMEMORY", 0x80004003: "E_POINTER", 0x8000FFFF: "E_UNEXPECTED"}
WinGetClass, WinClass, %WinTitle%
if !(WinClass == "PPTFrameClass")
return "Window class mismatch. (" WinClass ")"
ControlGet, hwnd, hwnd,, paneClassDC%paneClassDC#%, %WinTitle%
if (ErrorLevel)
return "Error accessing the control hWnd. (" ErrorLevel ")"
VarSetCapacity(IID_IDispatch, 16)
NumPut(0x46000000000000C0, NumPut(0x0000000000020400, IID_IDispatch, "Int64"), "Int64")
if (hr := DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", -16, "Ptr", &IID_IDispatch, "Ptr*", pacc, "UInt")) != 0
return "Error calling AccessibleObjectFromWindow. (" (hrVal[hr] != "" ? hrVal[hr] : Format("0x{:X}", hr)) ")"
window := ComObject(9, pacc, 1)
if ComObjType(window) != 9
return "Error wrapping the window object."
try return window.Application
catch e
return "Error accessing the application object. (" SubStr(e.message, 1, 10) ")"
}