4 Replies - 3423 Views - Last Post: 08 June 2012 - 03:00 PM Rate Topic: -----

#1 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 195
  • Joined: 10-March 12

website into dll

Posted 07 June 2012 - 07:04 AM

hello everyone.
i am trying to create a dll containing a webbrowser control. What i want it to do is this: i have a form which calls a function from that dll. the dll naigates to a webpage, say "www.google.com". after it navigates, it reads a string from the page body and executes some actions with it. The problem is, when the form calls the function inside the dll, the webpage is not loaded inside the dll, so there is no string to read. If i run the code of the dll as a windows application, the form loads, it navigates to the web site and reads the string... how should i modify the code inside the dll so when a form calls the funtion inside it, it first loads the webpage, and after that execute the called function? a sample of the code is here, this is the code which i compile as a dll:

Imports SpeechLib
'Imports System.Speech
'Imports System.Speech.Recognition

Public Class Form1
    Public WithEvents vox As New SpVoice
    Dim myText As String

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Enter Then
            If TextBox1.Text <> "" Then
                Dim htmlElements As HtmlElementCollection = WebBrowser1.document.GetElementsByTagName("input")
                For Each el As HtmlElement In htmlElements
                    If el.GetAttribute("name").Equals("input") Then
                        el.SetAttribute("value", TextBox1.Text)
                    End If
                Next
                For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
                    If element.GetAttribute("type") = "submit" Then
                        element.InvokeMember("click")
                    End If
                Next
                Timer1.Enabled = True
                TextBox1.Text = ""
                TextBox1.Focus()
            End If
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Focus()
    End Sub

    Private Sub ReadWebString(byval StringToRead as String)
        Dim htmlElements As HtmlElementCollection = WebBrowser1.document.GetElementsByTagName("input")
        For Each el As HtmlElement In htmlElements
            If el.GetAttribute("name").Equals("input") Then
                el.SetAttribute("value", StringToRead)
            End If
        Next
        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.GetAttribute("type") = "submit" Then
                element.InvokeMember("click")
            End If
        Next
        Timer1.Enabled = True
        TextBox1.Text = ""
        TextBox1.Focus()
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        myText = Me.WebBrowser1.document.Body.InnerText.Substring(Me.WebBrowser1.document.Body.InnerText.IndexOf("Santa"))
        If myText.StartsWith("Santa") Then
            Dim StartS As String
            Dim Ends As String
            StartS = myText.Remove(0, myText.IndexOf(":") + 2)
            Ends = StartS .Remove(StartS .LastIndexOf("You"))
            vox.Speak(Ends)             
        Else
            Console.WriteLine(myText)
        End If
    End Sub
End Class



and i want to call it from another form, like this:

ReadWebString("hello world!")



Is This A Good Question/Topic? 0
  • +

Replies To: website into dll

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: website into dll

Posted 07 June 2012 - 07:15 AM

My experience in this runs more to VB6 than VB.Net, but from what I can see, you still have to expose your WebBrowser control as a control to do what you want. Controls are libraries of UI devices, and you're trying to access state data from the visible aspect of the WebBrowser.

This looks like a good place to start reading. Even though the examples are in C#, they're simple enough to easily see what's going on.

This post has been edited by BobRodes: 07 June 2012 - 07:17 AM

Was This Post Helpful? 1
  • +
  • -

#3 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 195
  • Joined: 10-March 12

Re: website into dll

Posted 07 June 2012 - 01:10 PM

i see.... well, all i wanted to do was a program with speech and voice recognition capabilities, to which the users could ask a question (through voice), then it will recognize those words, search the a website for them (google for example), and read the results through speech synthesis... so, i wanted to use it as a dll because the user would not interract with the controls inside, nor do they need to see the interface, all interactions being done through voice...
but if this is not posible, then i guess i will use it as i have it now, making the user interface visible.. thanks anyway!
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: website into dll

Posted 08 June 2012 - 09:02 AM

I didn't say it wasn't possible. Have a look at the Google API, which allows you to automate google search engine requests without a web browser.
Was This Post Helpful? 1
  • +
  • -

#5 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 195
  • Joined: 10-March 12

Re: website into dll

Posted 08 June 2012 - 03:00 PM

well, based on some timers i finallt managed to solve it, and it works without the user interface... thanks a lot, anyway :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1