Thanks again, CJ. I think we're getting close. Here's my code:
[Reference added to COM: Sens Events TypeLibrary
(c:\windows\system32\SENS.dll]
Public Class Form1
Inherits System.Windows.Forms.Form
[Windows Form Designer generated code]
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles btnStart.Click
Dim loSENS As New SensEvents.SENSClass
AddHandler loSENS.DisplayUnlock, AddressOf MyScreenUnlockedHandler
End Sub
Private Sub MyScreenUnlockedHandler(ByVal UserName As String)
Me.txtScreenUnlocked.Text = Now().ToString
End Sub
End Class
When I run the project and click the button, I get an error on the Dim
loSENS as New SensEvents.SENSClass line:
"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in UI.exe
Additional information: COM object with CLSID
{D597CAFE-5B9F-11D1-8DD2-00AA004ABD5E} is either not valid or not registered."
When I look in RegEdit, I see that the AppID for
c:\windows\system32\SENS.DLL is {D3938AB0-5B9D-11D1-8DD2-00AA004ABD5E}, while
the TypeLib value is {D597DEED-5B9F-11D1-8DD2-00AA004ABD5E}
Where does the D597CAFE part of the CLSID shown in the error message come
from? In the VB solution explorer, the SensEvents reference shows the correct
identity (D597DEED-...).
Dunno what to make of all this.
CJ Taylor said:
Hi Leigh,
This is actually an event sink itself (note the handles clause, which can be
used when a variable is declared WithEvents). If you look up in your
Windows Forms Designer Generated Code Region you will see btnStart is
declared
Private WithEvents btnStart as System.Windows.Forms.Button
Which allows you to use the handles clause (and intellisense works well with
it)...
but enough about that..
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
AddHandler objContainingEvent.DisplayUnlock, AddressOf MyEventHandler
End Sub
Private Sub MyEventHandler(sender as object, e as System.EventArgs)
me.txtScreenUnlocked = Now().ToString()
End Sub
Thanks, CJ -- but the little details still escape me. Let's say I have a
simple Winform app with a btnStart button:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
'What goes in here? Let's say I want to write the current time
'to Me.txtScreenUnlocked when the DisplayUnlock event fires.
End Sub
:
Event Sinks = Event Handlers [procedures]
i.e. AddHandler MyClass.MyEvent, AddressOF MyEventHandler <- [Your event
sink method]
Does anyone have an example of VB.Net code that uses the ISenslogon
interface? The documentation says to "subscribe to the SENS events
that
interest you" and to "create a sink object". Whazza?
I want to be notified when the display has been unlocked or the
ScreenSaver
has been stopped. If someone can get me started with a simple example
in
VB,
that would be great.