2
Vote

NDde and Win Services

description

I've recently joined to a project which needs to connect to a legacy application using DDE. Our objective is to make a winservice which will be listening to a TCP/IP port to receive a command and send it to that legacy application through DDE, using Visual C++ 2005.
 
Our problem is that the service doesn't connect (when we do the "client->Connect()") to the legacy application. It is said that "The client failed to connect to 'IDS4|PACS_version'". However, if I try a normal application (I mean, not a winservice) with the same app and topic name, it works properly. Does anyone know how to solve it? I've put the code of the method below in case you can give us a hand. Anyway, thanks a lot.
 
Int32 port = 50308;
IPAddress^ address = IPAddress::Parse("127.0.0.1");
 
this->server = gcnew TcpListener(address,port);    
server->Start();
 
array<Byte>^ bytes = gcnew array<Byte>(256);
String^ data = nullptr;
 
stopping = false;
while (!stopping)
{
    TcpClient^ client = server->AcceptTcpClient();
    data = nullptr;
    // Get a stream Object* for reading and writing
    NetworkStream^ stream = client->GetStream();

    Int32 i;     
    // Loop to receive all the data sent by the client.
    while ((!stopping) && (i = stream->Read( bytes, 0, bytes->Length )))
    {
        // Translate data bytes to a ASCII String*.
        data = Text::Encoding::ASCII->GetString( bytes, 0, i );
 
        // Process the data sent by the client.
        data = data->ToUpper();
 
        String^ id;
        getIdPaciente(data, &id);
        array<Byte>^msg = Text::Encoding::ASCII->GetBytes(id);
        try
        {
            // Create a client that connects to 'myapp|mytopic'.
            DdeClient^ client = gcnew DdeClient("IDS4", "PACS_version");
 
            // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
            //client->Disconnected += OnDisconnected;
 
            // Connect to the server.  It must be running or an exception will be thrown.
            client->Connect();
 
            // Synchronous Execute Operation
            client->Execute("1 { exam_id <" + id + "> }", 60000);
       }
        catch (Exception^ e)
        {
            e->ToString();
        }

comments