Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text
- Public Class BuildString
- Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" ( _
- ByVal hwnd As Integer, _
- ByVal wMsg As Integer, _
- ByVal wParam As Integer, _
- ByVal lParam As Integer _
- ) As Integer
- Public Event StringOK(ByVal Result As String)
- Private hwnd As Integer = 0
- Private wMsg As Integer = 0
- Private wParam As Integer = 0
- Private lParam As String = ""
- Private tempA() As Byte = New Byte() {}
- Private enc As Encoding = Encoding.UTF8
- Public Property Encode() As Encoding
- Get
- Return enc
- End Get
- Set(ByVal value As Encoding)
- enc = value
- End Set
- End Property
- Public Sub BuildString(ByVal b As IntPtr)
- If b <> 0 Then
- 'build temp array
- Dim tempB(tempA.Length) As Byte
- tempA.CopyTo(tempB, 0)
- tempB(tempA.Length) = b
- ReDim tempA(tempB.Length - 1)
- tempB.CopyTo(tempA, 0)
- Else
- 'decode byte array to string
- Dim s As String
- If enc Is Encoding.UTF8 Then
- s = Encoding.UTF8.GetString(tempA)
- ElseIf enc Is Encoding.Unicode Then
- s = Encoding.Unicode.GetString(tempA)
- ElseIf enc Is Encoding.ASCII Then
- s = Encoding.ASCII.GetString(tempA)
- Else
- s = Encoding.Default.GetString(tempA)
- End If
- 'send out result string via event
- RaiseEvent StringOK(s)
- tempA = New Byte() {} ' Versuch 1, die letzte Nachricht zu löschen ... Fehlgeschlagen
- End If
- End Sub
- Public Sub PostString( _
- ByVal hwnd As Integer, _
- ByVal wMsg As Integer, _
- ByVal wParam As Integer, _
- ByVal lParam As String _
- )
- Dim ba() As Byte
- If enc Is Encoding.UTF8 Then
- ba = Encoding.UTF8.GetBytes(lParam)
- ElseIf enc Is Encoding.Unicode Then
- ba = Encoding.Unicode.GetBytes(lParam)
- ElseIf enc Is Encoding.ASCII Then
- ba = Encoding.ASCII.GetBytes(lParam)
- Else
- ba = Encoding.Default.GetBytes(lParam)
- End If
- Dim i As Integer
- For i = 0 To ba.Length - 1
- PostMessage(hwnd, wMsg, wParam, ba(i))
- Next
- PostMessage(hwnd, wMsg, wParam, 0)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement