This project is read-only.

Multiple items in one connection

Jul 23, 2009 at 3:25 AM

Since MathWorks (MATLAB) and Microsoft decided to do away with DDE functionality still in use by some widespread applications, I had to find an alternate way of creating hot links.  Using NDde, I tried creating a single connection to the data manager of the ESIGNAL financial data feed (winros.exe) and running multiple advisory links (multiple items).  The VB express 2008 test program started OK and then crashed.  I had a single OnAdvise call back function where I thought I could check the contents of args.Item, but that didn't work too well.  Does anyone know if it is possible to call multiple items on a single connection and how that's done in VB?

I also tried two connections with a single advisory link per connection.  That appears to work OK.  The working code is as follows:

Imports NDde.Client
Public Class Form1

    Dim client As DdeClient
    Dim client2 As DdeClient

    Delegate Sub SetTextCallback(ByVal [text] As String)
    Delegate Sub SetTextCallback2(ByVal [text] As String)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        client = New DdeClient("winros", "last")
        client.Connect()
        client.StartAdvise("6E U9", 1, True, 60000)
        AddHandler client.Advise, AddressOf OnAdvise

        client2 = New DdeClient("winros", "last")
        client2.Connect()
        client2.StartAdvise("6J U9", 1, True, 60000)
        AddHandler client2.Advise, AddressOf OnAdvise

    End Sub

    Private Sub OnAdvise(ByVal sender As Object, ByVal args As DdeAdviseEventArgs)
        Dim NewText As String = args.Text
        Dim NewText2 As String = args.Item

        If NewText2 = "6E U9" Then
            If Me.TextBox1.InvokeRequired Then
                ' It's on a different thread, so use Invoke.
                Dim d As New SetTextCallback(AddressOf SetText)
                Me.Invoke(d, New Object() {NewText})
            Else
                ' It's on the same thread, no need for Invoke.
                Me.TextBox1.Text = NewText
            End If
        ElseIf NewText2 = "6J U9" Then
            If Me.TextBox2.InvokeRequired Then
                ' It's on a different thread, so use Invoke.
                Dim b As New SetTextCallback2(AddressOf SetText2)
                Me.Invoke(b, New Object() {NewText})
            Else
                ' It's on the same thread, no need for Invoke.
                Me.TextBox2.Text = NewText
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim NewText As String = "Done"

        If client.IsConnected() Then client.Disconnect()
        If client2.IsConnected() Then client2.Disconnect()

        If Me.TextBox1.InvokeRequired Then
            ' It's on a different thread, so use Invoke.
            Dim d As New SetTextCallback(AddressOf SetText)
            Me.Invoke(d, New Object() {NewText})
        Else
            ' It's on the same thread, no need for Invoke.
            Me.TextBox1.Text = NewText
        End If

    End Sub
    Private Sub SetText(ByVal [text] As String)
        Me.TextBox1.Text = [text]
    End Sub
    Private Sub SetText2(ByVal [text] As String)
        Me.TextBox2.Text = [text]
    End Sub


End Class

 

Feb 20, 2010 at 5:02 PM

Did anyone figure this out?

Thank you!

Feb 1, 2015 at 3:08 PM
Hi FutsTdr,

Did you solve this issue?