SetValue and Release are not functions

前端 未结 1 444
北恋
北恋 2021-01-24 17:15

In summary: I searched MSDN and thought to create my own SetValue but I can\'t find any sourcecode for it. It\'s not in a DLL, its like InitPropVariantFromStr

1条回答
  •  时光说笑
    2021-01-24 18:00

    Solved, I had to use VTBL: https://github.com/Noitidart/_scratchpad/blob/master/IPropertyStore%20COM%20jsctypes.js

    The order of the defintions in the Vtbl matter big time. So make sure its correct if you want to do something with Vtbls

    var IPropertyStoreVtbl = new ctypes.StructType('IPropertyStoreVtbl');
    var IPropertyStore = new ctypes.StructType('IPropertyStore', [{
        'lpVtbl': IPropertyStoreVtbl.ptr
    }]);
    this.IPropertyStorePtr = new ctypes.PointerType(IPropertyStore);
    
    IPropertyStoreVtbl.define(
        [{ //start inherit from IUnknown
            'QueryInterface': ctypes.FunctionType(ctypes.stdcall_abi,
                this.HRESULT, [
                    IPropertyStore.ptr,
                    this.REFIID,    // riid
                    this.VOIDPTR    // **ppvObject
                ]).ptr
        }, {
            'AddRef': ctypes.FunctionType(ctypes.stdcall_abi,
                this.ULONG, [
                    IPropertyStore.ptr
                ]).ptr
        }, {
            'Release': ctypes.FunctionType(ctypes.stdcall_abi,
                this.ULONG, [
                    IPropertyStore.ptr
                ]).ptr
        }, { //end inherit from IUnknown //start IPropertyStore
            'GetCount': ctypes.FunctionType(ctypes.stdcall_abi,
                this.HRESULT, [
                    IPropertyStore.ptr,
                    this.DWORD.ptr  // *cProps
                ]).ptr
        }, {
            'GetAt': ctypes.FunctionType(ctypes.stdcall_abi,
                this.HRESULT, [
                    IPropertyStore.ptr,
                    this.DWORD,             // iProp
                    this.PROPERTYKEY.ptr    //*pkey
                ]).ptr
        }, {
            'GetValue': ctypes.FunctionType(ctypes.stdcall_abi,
                this.HRESULT, [
                    IPropertyStore.ptr,
                    this.REFPROPERTYKEY,    // key
                    this.PROPVARIANT.ptr    // *pv
                ]).ptr
        }, {
            'SetValue': ctypes.FunctionType(ctypes.stdcall_abi,
                this.HRESULT, [
                    IPropertyStore.ptr,
                    this.REFPROPERTYKEY,    // key
                    this.REFPROPVARIANT     // propvar
                ]).ptr
        }, {
            'Commit': ctypes.FunctionType(ctypes.stdcall_abi,
                this.HRESULT, [
                    IPropertyStore.ptr
                ]).ptr
        }]
    );
    

    Then to get the IPropertyStore of a window:

    var ppsPtr = new ostypes.IPropertyStorePtr();
    var hr_SHGetPropertyStoreForWindow = _dec('SHGetPropertyStoreForWindow')(cHwnd, IID_IPropertyStore.address(), ppsPtr.address()); 
    checkHRESULT(hr_SHGetPropertyStoreForWindow, 'SHGetPropertyStoreForWindow');
    var pps = ppsPtr.contents.lpVtbl.contents;
    

    now you can use IPropertyStore :: SetValue and IPropertyStore :: Release but make sure to pass the ppsPtr as first argument to them then the remaining arguments are what you would expect: var hr = pps.SetValue(ppsPtr, firstArgOf_SetValue, secondArgOf_SetValue)


    EDIT:

    adding copy paste runnable script from scratchpad. Copy and paste this: http://pastebin.mozilla.org/8429999

    this will do the equivalent of this XPCOM:

     var win = Services.wm.getMostRecentWindow(null);
     Cc["@mozilla.org/windows-taskbar;1"].getService(Ci.nsIWinTaskbar).setGroupIdForWindow(win, 'Contoso.Scratch')
    

    Yes its long but the good thing about it is, there is no XPCOM to set RelaunchCommand and RelaunchIconResource etc. Thats why js-ctypes is needed.

    0 讨论(0)
提交回复
热议问题