Click here to Skip to main content
13,558,765 members
Click here to Skip to main content

Stats

11.7K views
690 downloads
12 bookmarked
Posted 15 Apr 2012
Licenced CPOL

VB.NET wrappers for much of the Windows API

, 15 Apr 2012
Includes most API functions except for graphics.
UtilitiesLib
bin
Debug
sclib.dll
sclib.pdb
Release
sclib.dll
sclib.pdb
My Project
Application.myapp
vssver2.scc
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
Salience.Library.Resources.resources
sclib.dll
sclib.pdb
TempPE
My Project.Resources.Designer.vb.dll
UtilitiesLib.vbproj.GenerateResource.Cache
Release
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource-ResGen.read.1.tlog
GenerateResource-ResGen.write.1.tlog
Salience.Library.Resources.resources
sclib.dll
sclib.pdb
TempPE
My Project.Resources.Designer.vb.dll
UtilitiesLib.suo
Imports System.Runtime.InteropServices
Imports System.ComponentModel

Public Class CtrlMessagesListener

    <DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
    Private Shared Function SetConsoleCtrlHandler( _
        ByVal handler As MessageDelegate, _
        ByVal add As Boolean) As Integer
    End Function

    Private Const DESKTOP_READOBJECTS As Long = &H1

    ' A delegate type to be used as the handler routine 
    ' for SetConsoleCtrlHandler.
    Delegate Function MessageDelegate(ByVal type As ControlTypes) As Boolean

    ' An enumerated type for the control messages 
    ' sent to the handler routine.
    Public Enum ControlTypes
        CTRL_C_EVENT = 0
        CTRL_BREAK_EVENT
        CTRL_CLOSE_EVENT
        CTRL_LOGOFF_EVENT = 5
        CTRL_SHUTDOWN_EVENT
    End Enum

    Public Event ControlMessage(ByVal type As ControlTypes)

    Dim msgDelegate As MessageDelegate

    Public Sub New()
        msgDelegate = New MessageDelegate(AddressOf Me.MessageProc)
        Dim ret As Integer
        ret = SetConsoleCtrlHandler(msgDelegate, True)

        If ret = 0 Then
            Console.WriteLine("Unable to set Console Control Handler: " + New Win32Exception(Marshal.GetLastWin32Error()).Message, EventLogEntryType.Error)
        End If
    End Sub

    Private Function MessageProc(ByVal type As ControlTypes) As Boolean
        RaiseEvent ControlMessage(type)
    End Function

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

andrewbb@gmail.com
Architect
United States United States
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 15 Apr 2012
Article Copyright 2012 by andrewbb@gmail.com
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid