Imports System.Runtime.InteropServices Imports System Imports System.Runtime.CompilerServices Friend Class MSNWindow Implements IDisposable Public Sub New() Dim lpClassName As String = "MsnMsgrUIManager" Dim lpWndClass As New WNDCLASS.lpszClassName = lpClassName _ MSNWindow.dontDieOnMe = New WndProc(AddressOf MSNWindow.CustomWndProc) GC.KeepAlive(MSNWindow.dontDieOnMe) lpWndClass.lpfnWndProc = MSNWindow.dontDieOnMe Dim num As UInt16 = MSNWindow.RegisterClassW((lpWndClass)) Dim num2 As Integer = Marshal.GetLastWin32Error If ((num = 0) AndAlso (num2 <> &H582)) Then Throw New Exception("Could not register window class") End If Me.m_hwnd = MSNWindow.CreateWindowExW(0, lpClassName, String.Empty, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) End Sub Private Delegate Function WndProc(ByVal hWnd As IntPtr, ByVal msg As UInt32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr Private Structure WNDCLASS Public style As UInt32 Public lpfnWndProc As WndProc Public cbClsExtra As Integer Public cbWndExtra As Integer Public hInstance As IntPtr Public hIcon As IntPtr Public hCursor As IntPtr Public hbrBackground As IntPtr _ Public lpszMenuName As String _ Public lpszClassName As String End Structure Private Shared dontDieOnMe As WndProc Private Const ERROR_CLASS_ALREADY_EXISTS As Integer = &H582 Private m_disposed As Boolean Private m_hwnd As IntPtr Public Shared status As String = Nothing Private Structure COPYDATASTRUCT Public dwData As IntPtr Public cbData As Integer Public lpData As IntPtr End Structure Sub Dispose(ByVal disposing As Boolean) If (Not Me.m_disposed AndAlso (Me.m_hwnd <> IntPtr.Zero)) Then MSNWindow.DestroyWindow(Me.m_hwnd) Me.m_hwnd = IntPtr.Zero End If End Sub _ Private Shared Function DefWindowProcW(ByVal hWnd As IntPtr, ByVal msg As UInt32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr End Function _ Private Shared Function DestroyWindow(ByVal hWnd As IntPtr) As Boolean End Function _ Private Shared Function RegisterClassW(<[In]()> ByRef lpWndClass As WNDCLASS) As UInt16 End Function _ Private Shared Function CreateWindowExW(ByVal dwExStyle As UInt32, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As UInt32, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hWndParent As IntPtr, ByVal hMenu As IntPtr, ByVal hInstance As IntPtr, ByVal lpParam As IntPtr) As IntPtr End Function Private Shared Function CustomWndProc(ByVal hWnd As IntPtr, ByVal msg As UInt32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr If (msg = &H4A) Then Dim copydatastruct As COPYDATASTRUCT = DirectCast(Marshal.PtrToStructure(lParam, GetType(COPYDATASTRUCT)), COPYDATASTRUCT) Dim str As String = Marshal.PtrToStringUni(copydatastruct.lpData, (copydatastruct.cbData / 2)) Dim separator As String() = New String() {"\0"} Dim sourceArray As String() = str.Split(separator, StringSplitOptions.None) If (sourceArray(2) = "0") Then MSNWindow.status = Nothing Else Dim destinationArray As String() = New String((sourceArray.Length - 5) - 1) {} Array.Copy(sourceArray, 4, destinationArray, 0, (sourceArray.Length - 5)) MSNWindow.status = String.Format(sourceArray(3), DirectCast(destinationArray, Object())) End If End If Return MSNWindow.DefWindowProcW(hWnd, msg, wParam, lParam) End Function End Sub End Class