Hi all... Sean, Lexikos - can't thank you enough for all you've added to AHK... it makes life under Windows almost enjoyable.

No questions (ok... I do have one - at the very end) - I just thought I'd post the results of my beat-head-on-wall marathon the past day or so. I'm a unix admin... not new to programming.. but c/perl/shell/ruby/etc, especially coming from the unix world does nothing to prepare you for the convolutions you go through to make things happen on windows. To be fair... most of my problems were because I thought I had checked, a few times, to be sure I had the COM_L version in lib\, but somehow I had the one from COM... once that was corrected, things went really quickly.
Any chance COM and CLR (regular and _L versions, 32bit vs 64bit) could get a comment at the top, mentioning which variant it was? Would sure have made it easier to notice which version it was, without having to re-download from the forum, and compare file sizes.
Anyway - I finally got Lexikos' event handler example working with the latest AHK_L, COM_L and CLR_L. Which is amazing, since until 36 hours ago, I had never even looked as C#... or built anything with CLR. Now that I have the example working, hopefully I can implement a network address change daemon, that I can use to trigger other ahk scripts when adapters change state or address. Automate updating proxy settings, primarily, but I have other things too.
Biggest changes to get it working were converting everything to "." notation - which makes it much more readable too (double win). Oh, I changed the ahk handler function name (prefixed with "Ahk" now) so it would be less confusing which was being referred to in the various locations.
Revised EventHandler:
#Persistent
AhkEventHandler(vt, junk1, sender, junk2, eventArgs)
{
MsgBox, 0, Event Raised, % "sender: " COM_Invoke(sender,"ToString")
. "`neventArgs: " COM_Invoke(eventArgs,"ToString")
ExitApp
}
c# =
(
using System;
using System.Runtime.InteropServices;
class ObjectWithEvent {
public void RaiseEvent() {
if (OnEvent != null)
OnEvent(this, EventArgs.Empty);
}
public event EventHandler OnEvent;
public Delegate Delegate4FuncPtr(uint ptr, Type t) {
return Marshal.GetDelegateForFunctionPointer((IntPtr)ptr, t);
}
}
)
asmCor := CLR_LoadLibrary("mscorlib")
; Get typeof(System.EventHandler)
tEH := asmCor.GetType_2("System.EventHandler")
; Create Event Handling object
obj := CLR_CompileC#(c#, "System.dll").CreateInstance("ObjectWithEvent")
; Create a .NET Delegate for the AhkEventHandler() callback.
pEH := obj.Delegate4FuncPtr( RegisterCallback("AhkEventHandler"), tEH)
; Register the event handler. (Events export add_event() and remove_event()).
obj.add_OnEvent(COM_Parameter(13,pEH))
; Call the C# method which raises the event.
obj.RaiseEvent()
Return
What I hope to springboard to next: adapting
this to be the event receiver for network changes on my LAN and WiFi interfaces... a limited form of hald or d-bus for networking. If anyone knows of a better way I'm all ears. Anything except polling I mean - that I could manage (lots of options there - ifconfig, netsh, registry, etc), but subscribing to the event that's available has to be more efficient than anything using ifconfig or netsh (or even polling the registry keys for changes).
When I have something working in reasonable presentable shape - I'll be sure to post it.