-
Aug 14th, 2014, 08:39 PM
#1
Thread Starter
Lively Member
plz help convert code vb6 to .net
hello plz help convert code vb6 to .net
Code:
Option Explicit
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
' find window
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
' read message
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" _
(ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" _
(ByVal hwnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As String, _
ByVal fuFlags As Long, _
ByVal uTimeout As Long, _
lpdwResult As Long) As Long
Private Declare Function ObjectFromLresult Lib "oleacc" _
(ByVal lResult As Long, _
riid As UUID, _
ByVal wParam As Long, _
ppvObject As Any) As Long
Private Const SMTO_ABORTIFHUNG = &H2
Private Sub GetChildren(ByVal hwnd As Long)
Dim hwnd_embed As Long
Dim hwnd_parent As Long
Dim hwnd_child As Long
Dim doc As New HTMLDocument
hwnd_embed = FindWindowEx(hwnd, 0&, s h elll Embedding", vbNullString)
hwnd_parent = FindWindowEx(hwnd_embed, 0&, s h elll DocObject View", vbNullString)
hwnd_child = FindWindowEx(hwnd_parent, 0&, "Internet Explorer_Server", vbNullString)
If hwnd_child Then
Set doc = GetChildText(hwnd_child)
MsgBox doc.body.innerHTML
Else
' not found
End If
End Sub
Private Sub GetContainer()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "MobiLink")
If hwnd Then
Me.Caption = "MobiLink is Open"
GetChildren hwnd
Else
Me.Caption = "MobiLink is Closed"
End If
End Sub
Private Function GetChildText(ByVal hwnd As Long) As IHTMLDocument
Dim hwnd_msg As Long
Dim hwnd_result As Long
Dim hwnd_obj As Long
Dim IID_IHTMLDocument As UUID
hwnd_msg = RegisterWindowMessage("WM_HTML_GETOBJECT")
SendMessageTimeout hwnd, hwnd_msg, 0, 0, SMTO_ABORTIFHUNG, 1000, hwnd_result
If hwnd_result Then
' initialize the interface id
With IID_IHTMLDocument
.Data1 = &H626FC520
.Data2 = &HA41E
.Data3 = &H11CF
.Data4(0) = &HA7
.Data4(1) = &H31
.Data4(2) = &H0
.Data4(3) = &HA0
.Data4(4) = &HC9
.Data4(5) = &H8
.Data4(6) = &H26
.Data4(7) = &H37
End With
hwnd_obj = ObjectFromLresult(hwnd_msg, IID_IHTMLDocument, 0, GetChildText)
If hwnd_obj Then
' exception thrown
End If
End If
End Function
Private Sub Form_Load()
GetContainer
End Sub
-
Aug 14th, 2014, 09:51 PM
#2
Re: plz help convert code vb6 to .net
What have you tried and what issues did you encounter? The first rule to be aware of is that anywhere a VB6 API declaration uses Long, it's using a 32-bit number. In VB.NET, LOng is 64-bit and it's Integer that is 32-bit.
-
Aug 14th, 2014, 09:55 PM
#3
Re: plz help convert code vb6 to .net
(ByVal hwnd As Long
That'd be IntPtr not Long
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 14th, 2014, 11:16 PM
#4
Thread Starter
Lively Member
Re: plz help convert code vb6 to .net
Originally Posted by .paul.
(ByVal hwnd As Long
That'd be IntPtr not Long
Possible help me in that Modified code to vb.net?
Code:
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, riid As UUID, ByVal wParam As Long, ppvObject As Any) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As String, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Private Const SMTO_ABORTIFHUNG = &H2
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Function EnumChildProc(ByVal hwnd As Long, lParam As Long) As Long
If IsIE(hwnd) Then
Dim doc As New HTMLDocument
Set doc = GetIEText(hwnd)
MsgBox doc.body.innerHTML
Else
End If
EnumChildProc = 1
End Function
Function IsIE(hwnd As Long) As Boolean
Dim cName As String
cName = Space(100)
GetClassName hwnd, cName, 100
If InStr(cName, "Internet Explorer_Server") Then
IsIE = True
Else
IsIE = False
End If
End Function
Function GetIEText(ByVal hwnd As Long) As IHTMLDocument
Dim hwnd_msg As Long, hwnd_result As Long, hwnd_obj As Long
hwnd_msg = RegisterWindowMessage("WM_HTML_GETOBJECT")
Dim IID_IHTMLDocument As UUID
SendMessageTimeout hwnd, hwnd_msg, 0, 0, SMTO_ABORTIFHUNG, 1000, hwnd_result
If hwnd_result Then
With IID_IHTMLDocument
.Data1 = &H626FC520
.Data2 = &HA41E
.Data3 = &H11CF
.Data4(0) = &HA7
.Data4(1) = &H31
.Data4(2) = &H0
.Data4(3) = &HA0
.Data4(4) = &HC9
.Data4(5) = &H8
.Data4(6) = &H26
.Data4(7) = &H37
End With
hwnd_obj = ObjectFromLresult(hwnd_msg, IID_IHTMLDocument, 0, GetChildText)
If hwnd_obj Then
End If
End If
End Function
-
Aug 15th, 2014, 08:10 AM
#5
Re: plz help convert code vb6 to .net
Originally Posted by .paul.
(ByVal hwnd As Long
That'd be IntPtr not Long
In C it's IntPtr... which in VB6 was a Long... and in VB.NET it would be an Integer.
Originally Posted by johnmarkt
Possible help me in that Modified code to vb.net?
Code:
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, riid As UUID, ByVal wParam As Long, ppvObject As Any) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As String, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Private Const SMTO_ABORTIFHUNG = &H2
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Function EnumChildProc(ByVal hwnd As Long, lParam As Long) As Long
If IsIE(hwnd) Then
Dim doc As New HTMLDocument
Set doc = GetIEText(hwnd)
MsgBox doc.body.innerHTML
Else
End If
EnumChildProc = 1
End Function
Function IsIE(hwnd As Long) As Boolean
Dim cName As String
cName = Space(100)
GetClassName hwnd, cName, 100
If InStr(cName, "Internet Explorer_Server") Then
IsIE = True
Else
IsIE = False
End If
End Function
Function GetIEText(ByVal hwnd As Long) As IHTMLDocument
Dim hwnd_msg As Long, hwnd_result As Long, hwnd_obj As Long
hwnd_msg = RegisterWindowMessage("WM_HTML_GETOBJECT")
Dim IID_IHTMLDocument As UUID
SendMessageTimeout hwnd, hwnd_msg, 0, 0, SMTO_ABORTIFHUNG, 1000, hwnd_result
If hwnd_result Then
With IID_IHTMLDocument
.Data1 = &H626FC520
.Data2 = &HA41E
.Data3 = &H11CF
.Data4(0) = &HA7
.Data4(1) = &H31
.Data4(2) = &H0
.Data4(3) = &HA0
.Data4(4) = &HC9
.Data4(5) = &H8
.Data4(6) = &H26
.Data4(7) = &H37
End With
hwnd_obj = ObjectFromLresult(hwnd_msg, IID_IHTMLDocument, 0, GetChildText)
If hwnd_obj Then
End If
End If
End Function
Ah, yeah, ok... so your coping and pasting skills work, but you haven't changed a thing.
First thing you should have done is what jmc suggested
What have you tried and what issues did you encounter? The first rule to be aware of is that anywhere a VB6 API declaration uses Long, it's using a 32-bit number. In VB.NET, LOng is 64-bit and it's Integer that is 32-bit.
then the next thing is to probably copy it and paste it into a VB.NET module file... and then look at the errors and make corrections as needed.
-tg
-
Aug 15th, 2014, 10:54 AM
#6
Re: plz help convert code vb6 to .net
Originally Posted by techgnome
In C it's IntPtr... which in VB6 was a Long... and in VB.NET it would be an Integer.
In C it is actually an HWND, which is several levels of alias for a void*. In .NET, you can use an Integer for that and a lot of people do but, as .paul. indicates, any parameter intended to represent a pointer or handle ideally should be an IntPtr.
-
Aug 15th, 2014, 11:00 AM
#7
Re: plz help convert code vb6 to .net
I didn't realize that IntPtr had been defined as a type in .NET... good to know.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|