FhConfigMgr, COM without IDispatch

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LogicDaemon
Posts: 21
Joined: 21 Feb 2014, 01:22

FhConfigMgr, COM without IDispatch

19 Jun 2018, 10:45

Hi.

What I want is to implement SprintDLL script written in https://superuser.com/a/1289407 with AutoHotkey. That script configures file history in Windows.

And meanwhile, I'd like to learn about COM more.

Currently, I have troubles with basic function calling. As I understand, FhConfigMgr("LoadConfiguration") should return a value (S_OK or some E_…), but currently it returns empty string. Here's what I got:

Code: Select all

MsgBox % "LoadConfiguration → " FhConfigMgr("LoadConfiguration")
MsgBox % "CreateDefaultConfiguration → " FhConfigMgr("CreateDefaultConfiguration", "Int", TRUE)

FhConfigMgr()
ExitApp

FhConfigMgr(ByRef fn := "", args*) { ; https://technet.microsoft.com/ru-ru/hh829807?f=255&MSPPError=-2147217396#methods
    static CLSID_IFhConfigMgr := "{6A5FEA5B-BF8F-4EE5-B8C3-44D8A0D7331C}"
         , CLSID_FhConfigMgr := "{ED43BB3C-09E9-498a-9DF6-2177244C6DB4}"
         , tbl := ""
                ;    IUnknown:
                ;      0 QueryInterface  -- use ComObjQuery instead
                ;      1 AddRef          -- use ObjAddRef instead
                ;      2 Release         -- use ObjRelease instead
                ; rest @ https://github.com/tpn/winsdk-10/blob/master/Include/10.0.10240.0/um/FhCfg.h
         , fnMap := { LoadConfiguration: 3
                    , CreateDefaultConfiguration: 4
                    , saveConfiguration: 5
                    , AddRemoveExcludeRule: 6
                    , GetIncludeExcludeRules: 7
                    , GetLocalPolicy: 8
                    , SetLocalPolicy: 9
                    , GetBackupStatus: 10
                    , SetBackupStatus: 11
                    , GetDefaultTarget: 12
                    , ValidateTarget: 13
                    , ProvisionAndSetNewTarget: 14
                    , ChangeDefaultTargetRecommendation: 15
                    , QueryProtectionStatus: 16 }

    If (tbl=="")
        tbl := ComObjCreate(CLSID_FhConfigMgr, CLSID_IFhConfigMgr)
    If (fn=="")
        return ObjRelease(tbl)
    Else
        return DllCall(vtable(tbl, fnMap[fn]), args*)
}

vtable(ptr, n) { ;example from ahk help
    ; NumGet(ptr+0) returns the address of the object's virtual function
    ; table (vtable for short). The remainder of the expression retrieves
    ; the address of the nth function's address from the vtable.
    return NumGet(NumGet(ptr+0), n*A_PtrSize)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 369 guests