[FUNC]ObjRegisterActive
来源:互联网 发布:java 微信网页授权 编辑:程序博客网 时间:2024/06/02 00:59
https://autohotkey.com/boards/viewtopic.php?t=6148
函数如下:
/* ObjRegisterActive(Object, CLSID, Flags:=0) Registers an object as the active object for a given class ID. Requires AutoHotkey v1.1.17+; may crash earlier versions. Object: Any AutoHotkey object. CLSID: A GUID or ProgID of your own making. Pass an empty string to revoke (unregister) the object. Flags: One of the following values: 0 (ACTIVEOBJECT_STRONG) 1 (ACTIVEOBJECT_WEAK) Defaults to 0. Related: http://goo.gl/KJS4Dp - RegisterActiveObject http://goo.gl/no6XAS - ProgID http://goo.gl/obfmDc - CreateGUID()*/ObjRegisterActive(Object, CLSID, Flags:=0) { static cookieJar := {} if (!CLSID) { if (cookie := cookieJar.Remove(Object)) != "" DllCall("oleaut32\RevokeActiveObject", "uint", cookie, "ptr", 0) return } if cookieJar[Object] throw Exception("Object is already registered", -1) VarSetCapacity(_clsid, 16, 0) if (hr := DllCall("ole32\CLSIDFromString", "wstr", CLSID, "ptr", &_clsid)) < 0 throw Exception("Invalid CLSID", -1, CLSID) hr := DllCall("oleaut32\RegisterActiveObject" , "ptr", &Object, "ptr", &_clsid, "uint", Flags, "uint*", cookie , "uint") if hr < 0 throw Exception(format("Error 0x{:x}", hr), -1) cookieJar[Object] := cookie}
测试:To try, run both of the following files:
Host.ahk
; Register our object so that other scripts can get to it. The second; parameter is a GUID which I generated. You should generate one unique; to your script. You can use [CreateGUID](http://goo.gl/obfmDc).ObjRegisterActive(ActiveObject, "{6B39CAA1-A320-4CB0-8DB4-352AA81E460E}")#PersistentOnExit RevokereturnRevoke:; This "revokes" the object, preventing any new clients from connecting; to it, but doesn't disconnect any clients that are already connected.; In practice, it's quite unnecessary to do this on exit.ObjRegisterActive(ActiveObject, "")ExitApp; This is a simple class (object) that clients will interact with.; You can register any object; it doesn't have to be a class.class ActiveObject { ; Simple message-passing example. Message(Data) { MsgBox Received message: %Data% return 42 } ; "Worker thread" example. static WorkQueue := [] BeginWork(WorkOrder) { this.WorkQueue.Insert(WorkOrder) SetTimer Work, -100 return Work: ActiveObject.Work() return } Work() { work := this.WorkQueue.Remove(1) ; Pretend we're working. Sleep 5000 ; Tell the boss we're finished. work.Complete(this) } Quit() { MsgBox Quit was called. DetectHiddenWindows On ; WM_CLOSE=0x10 PostMessage 0x10,,,, ahk_id %A_ScriptHwnd% ; Now return, so the client's call to Quit() succeeds. }}
Client.ahk
; Get an active something.x := ComObjActive("{6B39CAA1-A320-4CB0-8DB4-352AA81E460E}"); Make up a property. It's an AutoHotkey object, after all.x.Name := "Bob"; Call a method.x.Message("Hello, world!"); Queue some work to be done. We'll be notified when it's finished.x.BeginWork({Complete: Func("Completed")})#PersistentCompleted(work, worker) { MsgBox % worker.Name " finished work." worker.Quit() ; Fire? ; PostMessage allows us to return before closing. DetectHiddenWindows On ; WM_CLOSE=0x10 PostMessage 0x10,,,, ahk_id %A_ScriptHwnd%}
0 0
- [FUNC]ObjRegisterActive
- func
- func
- func,func(),new func()的区别
- callback func
- FUNC 使用指南
- Func 委托
- Func 委托
- func安装
- Func,Action
- Func委托
- Func用法
- Golang func
- swift func
- 08-func
- 函数 Func
- go-func
- [FUNC]ArrayToGuiString
- 线段树从零开始
- 代码整洁之道读书笔记(六)
- hibernate查询
- http1.0和1.1的区别
- 刘汝佳《算法竞赛入门经典》推荐题目
- [FUNC]ObjRegisterActive
- <<Linux内核完全剖析 --基于0.12内核>>学习笔记 第4章 80x86保护模式及其编程 4.5 保护
- Swift-计算属性
- ZZUOJ 10496: Cross the River (最短路 Dij 青蛙过河)
- html中图片的添加
- action获取request和session
- 最牛b的编码套路
- 关于Ubuntu下XXis not marked as executable. it may be dangerous to run. 程序无法执行问题
- MySQL数据库高可用性架构汇总