DDE server not establishing connection when in hosted mode

948 views Asked by At

I have a Winforms application which hosts a C++ application (SUMATRA pdf viewer with some modifications) inside one of its controls.

I want to be able to sent DDE both ways, which works fine when the C++ is stand-alone. However, in hosted mode, I cant initiate DDE connection from Winforms app to Sumatra.

I use NDDe in C#, here is my code:

    class SumatraCommander : DdeClient
{
    public SumatraCommander() : base("SUMATRA", "control") 
    {

    }


    public void MoveDocuments(ClientsQuestion question)
    {
        if (!this.IsConnected) this.Connect(); // this line fails only when sumatra 
//is hosted
    }
}

And this is winapi message handling from Sumatra

case WM_DDE_INITIATE:           
        return OnDDEInitiate(hwnd, wParam, lParam);

Initiate function:

LRESULT OnDDEInitiate(HWND hwnd, WPARAM wparam, LPARAM lparam)
{
DBG_OUT("received WM_DDE_INITIATE from %p with %08lx\n", (HWND)wparam, lparam);

ATOM aServer = GlobalAddAtom(PDFSYNC_DDE_SERVICE);
ATOM aTopic = GlobalAddAtom(PDFSYNC_DDE_TOPIC);

if (LOWORD(lparam) == aServer && HIWORD(lparam) == aTopic) {
    if (!IsWindowUnicode((HWND)wparam))
        DBG_OUT("The client window is ANSI!\n");
    DBG_OUT("Sending WM_DDE_ACK to %p\n", (HWND)wparam);
    SendMessage((HWND)wparam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(aServer, 0));
}
else {
    GlobalDeleteAtom(aServer);
    GlobalDeleteAtom(aTopic);
}
return 0;
}

Will it help, if I override message handling of the C# Winforms control, in which i put the Sumatra viewer?

Or is there something wrong in the C++ code?

Or is it generally not possible to be a DDE server when I am hosted in another control?

Thanks for replies

1

There are 1 answers

0
Tomas Grosup On BEST ANSWER

It turned out, that this is not possible. In hosted mode, the host application needs to be the DDE server instead.