Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » VB.NET » HowTo » Downloads
 
Add your own
alternative version

ByPass difficult Automation and add applications "as is" in your .NET application

, 28 Dec 2004
Fed up with automation? Need to add components as is to your application? Try this out.
bypassautomation.zip
ByPassAutomation
bin
ByPassAutomation.exe
MasteringAssmblyInfoFile.exe
ByPassAutomation.vbproj.user
interactwithapplications.zip
InteractWithApplications
bin
AxInterop.SHDocVw.dll
GetBrowserDom.exe
InteractWithApplications.exe
Interop.SHDocVw.dll
WindowsApplication2.exe
InteractWithApplications.vbproj.user
Imports mshtml
Imports System.Text
Imports System.Runtime.InteropServices

Public Class IEDom

    Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Int32, ByRef riid As System.Guid, ByVal wParam As Int32, ByRef ppvObject As IHTMLDocument) As Int32
    Dim win32 As New Win32Functions
    Public Function IEDOMFromhWnd(ByVal hWnd As IntPtr) As IHTMLDocument
        Dim IID_IHTMLDocument As System.Guid = New System.Guid("626FC520-A41E-11CF-A731-00A0C9082637")
        Dim hWndChild As Int32
        Dim lRes As Int32
        Dim lMsg As Int32
        Dim hr As Int32

        If Not hWnd.Equals(0) Then

            If Not IsIEServerWindow(hWnd) Then

                ' Get 1st child IE server window
                win32.EnumChildWindows(hWnd, AddressOf EnumChild, hWnd)

            End If

            If Not hWnd.Equals(0) Then

                ' Register the message
                lMsg = win32.RegisterWindowMessage("WM_HTML_GETOBJECT")

                ' Get the object
                Call win32.SendMessageTimeout(hWnd, lMsg, 0, 0, _
                     win32.SMTO_ABORTIFHUNG, 1000, lRes)

                If lRes Then

                    ' Get the object from lRes
                    hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, IEDOMFromhWnd)

                    If hr Then Throw New COMException(hr)

                End If

            End If

        End If

    End Function

    Private Function EnumChild(ByVal hWnd As IntPtr, ByRef lParam As IntPtr) As Int32

        If IsIEServerWindow(hWnd) Then
            lParam = hWnd
        Else
            EnumChild = 1
        End If

    End Function

    Private Function IsIEServerWindow(ByVal hWnd As IntPtr) As Boolean
        Dim Res As Int32
        Dim ClassName As StringBuilder = New StringBuilder(100)

        ' Get the window class name
        Res = win32.GetClassName(hWnd, ClassName, ClassName.MaxCapacity)
        IsIEServerWindow = StrComp( _
                 ClassName.ToString(), _
                 "Internet Explorer_Server", _
                 CompareMethod.Text) = 0

    End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Armoghan Asif
Architect
Pakistan Pakistan
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 29 Dec 2004
Article Copyright 2004 by Armoghan Asif
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid