DDE Library

skipper

Member
Licensed User
Some time ago I asked Erel if I could ask help to the forum gurus to convert, or better, to make compatible with B4PPC, an open source library found on web.

The error reported by B4PPC when adding the library was "an object with the same name has already been added". Andrew was so kind to give me an explanation of the error and, based on his response and other readings on the net, I tried to deal with the error by myself. Unfortunately my C knowledge is very scarce, and that's why I decided to ask for help.

The library is a wrapper for the DDE functions in DDEML, it is written in C # and works without problems in #SharpDevelop. I need to interface some apps to other programs via DDE (Acrobat Reader, for example) and, even if Microsoft considers dead the DDE, often it seems to be the only direct and simple way to communicate with other programs.

I know that this community is very generous, but I don't want that others are wasting their time for free just for me. If there is any volunteer, please contact me in private for details and costs of conversion.

Thanks in advance for the help,
Mimmo

PS. I can't attach the library source code, even zipped, it is too big. Here is the link.

NDde
 

agraham

Expert
Licensed User
Longtime User
That is an enormous library! I don't know enough about DDE to even start to understand it. Do you already know how to use the objects in that library?

Would something simpler do?
Do you want a client or a server or both?
Do the following look as though you might know what they do?

Initiate;
ACK;
UnAdvise;
Request;
Poke;
Execute;
Data;
Advise;
Terminate;
InitACK;
 

skipper

Member
Licensed User
Hello Andrew and thanks for spending your time for me!

Yes, I know! It is very huge. For my needs, It should be enough to have a Client to be able to interface with other applications. With Acrobat Reader, for example, I need to start a conversation with him and then send some Execute statements.

If you have a look at DDE Message of Acrobat and Adobe Reader , you will have an idea. Clicking on any DDE message, you will see some VB code. The site is referencing to the DDE funtionality of Acrobat SDK.

Well, as you said it's a very huge library, and not all methods are clear to me, I'm still exploring them. My little DDE knowledge derives from VB6, where the DDE capabilities were built into the TextBox, Label and Form components. I don't know what you mean (sorry but also my english is very bad) but, looking at the command list you wrote it seems to me that:

Initiate; initiate and terminate a DDE conversation
Terminate;

Advise;
UnAdvise; Open and close a channel with the server on a specific Item, generating an event on every change of the Item value. You can trap the event and do a specific task. See my short sample code

Request; Request a specific Item data
Poke; Sends some data to the server
Execute; Executes a specific command on the server
Data; ??
ACK; ??ACKnoledge
InitACK; ?? I suppose it should be a conversation with ACKnoledge from the server

Here is a chunk of a short sample I wrote in #sharpdevelop (modifying one of the vb samples included in the source library) to interface my trading platform and collect data.

B4X:
Imports System.Text
Imports NDde.Client

'-- connection string format for Sella trading
'-- DDEXT|DR!MINIC000

Public Class MainForm
    '--Private WithEvents client As New DdeClient("myapp", "mytopic", Me)
    Private WithEvents client As New DdeClient("DDEXT", "DR", Me)

    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       btnDisconnect.Enabled = False
       btnConnect.Enabled = True
    End Sub

    Private Sub client_Advise(ByVal sender As Object, ByVal e As NDde.Client.DdeAdviseEventArgs) Handles client.Advise
       Select Case e.Item
          Case "MINIC070"
             txtBid.Text = e.Text
          Case "MINIC060"
             txtAsk.Text = e.text
          Case "MINIC000"
             txtLast.Text = e.Text
          Case "MINIC007"
             txtTime.Text = e.Text
          Case "MINIC014"
             txtVolume.Text = e.Text
       End Select
        
    End Sub

    Private Sub client_Disconnected(ByVal sender As Object, ByVal e As NDde.Client.DdeDisconnectedEventArgs) Handles client.Disconnected
        displayTextBox.Text = _
         "OnDisconnected: " + _
         "IsServerInitiated=" + e.IsServerInitiated.ToString() + " " + _
         "IsDisposed=" + e.IsDisposed.ToString()
    End Sub
    
    Sub BtnConnectClick(sender As Object, e As EventArgs)
       btnConnect.Enabled = False
       btnDisconnect.Enabled = True
       Try
            ' Connect to the server.  It must be running or an exception will be thrown.
            client.Connect()

            '--Advise Loop Format:
            '--client.StartAdvise("myitem", 1, True, 60000)
            '--Last Volume:   =DDEXT|DR!'MINIC014'
            '--Time:       =DDEXT|DR!'MINIC007'
            '--Bid:       =DDEXT|DR!'MINIC060'
            '--Ask:      =DDEXT|DR!'MINIC070'
            '--Last Price:   =DDEXT|DR!'MINIC000'
            
            client.StartAdvise("MINIC070", 1, True, 60000)
            client.StartAdvise("MINIC060", 1, True, 60000)
            client.StartAdvise("MINIC000", 1, True, 60000)
            client.StartAdvise("MINIC007", 1, True, 60000)
            client.StartAdvise("MINIC014", 1, True, 60000)
     
        Catch ex As Exception
            displayTextBox.Text = ex.Message
        End Try
    End Sub
    
    Sub BtnDisconnectClick(sender As Object, e As EventArgs)
       client.Disconnect()
       txtBid.Text = ""
   txtAsk.Text = ""
       txtLast.Text = ""
       txtTime.Text = ""
       txtVolume.Text = ""
    End Sub
End Class

I found some simplest DDE samples (an OCX witten in C++), I'll have a look just to know if it includes all what I need. May be it will simpler to convert...
I'll let you know.

Many thanks
Mimmo
 

agraham

Expert
Licensed User
Longtime User
It's a bit too complicated to port NDde.dll port to Basic4ppc without loads of editing to stop unwanted stuff appearing as objects. Here's a Basic4ppc wrapper library. It only exposes the Client at the moment. Method, property and event names are as far as possible the same as in the NDde Documentation.chm help file.
 

Attachments

  • DDE0.1.zip
    2.9 KB · Views: 242
Last edited:

skipper

Member
Licensed User
Andrew, my hero! Thank you very much!

I tried immediately the library and it seems to work. As you see, I was able to interface my trading platform and the data shown were obtained in a loop with the Request function.

Unfortunately, I was not able to hook the AdviseEvent and DisconnectedEvent events. I tried with ddeClient_AdviseEvent and ddeClient_DisconnectedEvent but they do not fired. Certainly I did not understand how they were implemented in the wrapper.

Also, I can not understand how to reference DdeAdviseEventArgs and DdeDisconnectedEventArgs (eg. Advisedata, AdviseFormat, AdviseItem and AdviseText should be fields/properties of DdeAdviseEventArgs).

Andrew, you are doing me a very big favor. Let me know, please how to say thank you.

Mimmo
 

Attachments

  • dde.PNG
    10.6 KB · Views: 313

agraham

Expert
Licensed User
Longtime User
Events are posing a problem. When I try to implement them as normal Basi4ppc events I get a hang no matter what I try, even if I run them on a separate thread. I suspect that because DDE uses Window Messages the events are being called from within the threads message loop and that is causing a deadlock of some sort that I don't understand.

However I seem to have got them working by bypassing the normal event structure and calling the events Subs directly, luckily something that I developed originally for my Threading library.

You can't reference the EventArgs from within Basic4ppc, only the event code called by the NDde library can get at them. As is usual with Basic4ppc libraries I will store their contents, where relevant, as properties that you can access in your "event" code. I'll post an update, probably tomorrow, once I have things cleaned up a bit.
 

agraham

Expert
Licensed User
Longtime User
I've got events working and provided DdeClient, DdeMonitor and DdeServer objects. I'm fairly happy with the client and monitor but I don't fully understand the operation of the server so it will most probably need more work on it.
 

Attachments

  • DDE0.2.zip
    6.4 KB · Views: 253

skipper

Member
Licensed User
:sign0060: :wav: :sign0098:

Unbelievable, the client works great!
DDE interface with Metatrader requesting 12 major quotes...

This is for fun.... tomorrow I'll test with seriously with Acrobat....

Thank you, thank you so much!

Mimmo

PS. I really need to know how to say thank you... please PM me!!!
 

Attachments

  • TestMT4.sbp
    2.4 KB · Views: 234
Cookies are required to use this site. You must accept them to continue using the site. Learn more…