Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Module Module1
<StructLayout(LayoutKind.Sequential)> _
Public Structure EDITSTREAM
<MarshalAs(UnmanagedType.I4)> Dim dwCookie As Integer ' /* user value passed to callback as first parameter */
<MarshalAs(UnmanagedType.I4)> Dim dwError As Integer ' /* last error */
Dim pfnCallback As LoadCallBackDelegate 'EDITSTREAMCALLBACK
End Structure
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As EDITSTREAM) As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As EDITSTREAM) As Integer
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As Integer, ByVal lpvSource As Integer, ByVal cbCopy As Integer)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As Integer, ByVal lpvSource As IntPtr, ByVal cbCopy As Integer)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As String, ByVal lpvSource As IntPtr, ByVal cbCopy As Integer)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As IntPtr, ByVal lpvSource As Integer, ByVal cbCopy As Integer)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As String, ByVal lpvSource As String, ByVal cbCopy As Integer)
Public Structure OVERLAPPED
Dim Internal As Integer
Dim InternalHigh As Integer
Dim offset As Integer
Dim OffsetHigh As Integer
Dim hEvent As Integer
End Structure
Public Const OFS_MAXPATHNAME As Short = 128
<StructLayout(LayoutKind.Sequential)> _
Public Structure OFSTRUCT
Dim cBytes As Byte
Dim fFixedDisk As Byte
Dim nErrCode As Short
Dim Reserved1 As Short
Dim Reserved2 As Short
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=OFS_MAXPATHNAME)> _
Dim szPathName() As Byte
Public Sub Initialize()
ReDim szPathName(OFS_MAXPATHNAME)
End Sub
End Structure
' Streaming support:
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1016"'
Public Declare Function WriteFile Lib "kernel32" (ByVal hFile As Integer, ByRef lpBuffer As Integer, ByVal nNumberOfBytesToWrite As Integer, ByRef lpNumberOfBytesWritten As Integer, ByVal lpOverlapped As Integer) As Integer 'lpOverlapped As OVERLAPPED) As Long
'UPGRADE_WARNING: Structure OFSTRUCT may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1050"'
Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, ByRef lpReOpenBuff As OFSTRUCT, ByVal wStyle As Integer) As Integer
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1016"'
Public Declare Function ReadFile Lib "kernel32" (ByVal hFile As Integer, ByRef lpBuffer As String, ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer, ByVal lpOverlapped As Integer) As Integer 'lpOverlapped As OVERLAPPED) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Public Const OF_CANCEL As Short = &H800S
Public Const OF_CREATE As Short = &H1000S
Public Const OF_DELETE As Short = &H200S
Public Const OF_EXIST As Short = &H4000S
Public Const OF_PARSE As Short = &H100S
Public Const OF_PROMPT As Short = &H2000S
Public Const OF_REOPEN As Short = &H8000S
Public Const OF_SHARE_COMPAT As Short = &H0S
Public Const OF_SHARE_DENY_NONE As Short = &H40S
Public Const OF_SHARE_DENY_READ As Short = &H30S
Public Const OF_SHARE_DENY_WRITE As Short = &H20S
Public Const OF_SHARE_EXCLUSIVE As Short = &H10S
Public Const OF_VERIFY As Short = &H400S
Public Const OF_WRITE As Short = &H1S
Public Const OF_READ As Short = &H0S
Public Const OF_READWRITE As Short = &H2S
' /* stream formats */
'Public Const SF_TEXT = &H1
'Public Const SF_RTF = &H2
Public Const WM_USER As Short = &H400S
Public Const SF_RTFNOOBJS As Short = &H3S ' /* outbound only */
Public Const SF_TEXTIZED As Short = &H4S ' /* outbound only */
Public Const SF_UNICODE As Short = &H10S ' /* Unicode file of some kind */
Public Const EM_STREAMIN As Integer = (WM_USER + 73)
Public Const EM_STREAMOUT As Integer = (WM_USER + 74)
' /* EM_SETCHARFORMAT wParam masks */
Public Const SCF_SELECTION As Integer = &H1
Public Const SCF_WORD As Integer = &H2
Public Const SCF_DEFAULT As Integer = &H0 '// set the default charformat or paraformat
Public Const SCF_ALL As Integer = &H4 '// not valid with SCF_SELECTION or SCF_WORD
Public Const SCF_USEUIRULES As Integer = &H8 '// modifier for SCF_SELECTION; says that
' // the format came from a toolbar, etc. and
' // therefore UI formatting rules should be
' // used instead of strictly formatting the
' // selection.
Private m_sText As String
Private m_lPos As Integer
Private m_lLen As Integer
Private m_bFileMode As Boolean
Private m_lObj As Integer
Public Delegate Function LoadCallBackDelegate(ByVal dwCookie As Integer, ByVal lPtrPbBuff As IntPtr, ByVal cb As Integer, ByVal pcb As Integer) As Integer
Public Property FileMode() As Boolean
Get
FileMode = m_bFileMode
End Get
Set(ByVal Value As Boolean)
m_bFileMode = Value
m_lPos = 0
m_lLen = -1
End Set
End Property
Public Function LoadCallBack(ByVal dwCookie As Integer, ByVal lPtrPbBuff As IntPtr, ByVal cb As Integer, ByVal pcb As Integer) As Integer
Dim sBuf As String
Dim b() As Byte
Dim lLen As Integer
Dim lRead As Integer
If (m_bFileMode) Then
ReadFile(dwCookie, sBuf, cb, pcb, 0)
MsgBox(System.Text.Encoding.UTF8.GetString(b))
'ReDim lPtrPbBuff(4094 - 1)
'ReadFile(dwCookie, lPtrPbBuff, cb, pcb, 0)
'MsgBox(System.Text.Encoding.UTF8.GetString(lPtrPbBuff))
'CopyMemory(lRead, lPtrPbBuff(0), 4)
If (lRead < cb) Then
' Complete:
Return 0
Else
' More to read:
Return 0
End If
m_lPos = m_lPos + lRead
End If
End Function