Results 1 to 7 of 7

Thread: plz help convert code vb6 to .net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2014
    Posts
    83

    Exclamation 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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: plz help convert code vb6 to .net

    (ByVal hwnd As Long

    That'd be IntPtr not Long

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2014
    Posts
    83

    Exclamation Re: plz help convert code vb6 to .net

    Quote Originally Posted by .paul. View Post
    (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

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: plz help convert code vb6 to .net

    Quote Originally Posted by .paul. View Post
    (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.

    Quote Originally Posted by johnmarkt View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: plz help convert code vb6 to .net

    Quote Originally Posted by techgnome View Post
    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.

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width