DDE 服务器在托管模式下未建立连接

发布于 2024-12-28 04:39:19 字数 1487 浏览 0 评论 0原文

我有一个 Winforms 应用程序,它在其控件之一内托管一个 C++ 应用程序(经过一些修改的 SUMATRA pdf 查看器)。

我希望能够双向发送 DDE,这当 C++ 独立时工作正常。但是,在托管模式下,我无法从 Winforms 应用程序启动 DDE 连接到苏门答腊岛。

我在 C# 中使用 NDDe,这是我的代码:

    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
    }
}

这是来自 Sumatra

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

Initiate 函数的 winapi 消息处理:

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;
}

如果我覆盖 C# Winforms 控件(我在其中放置了 Sumatra 查看器)的消息处理,它会有帮助吗?

还是C++代码有问题?

或者当我托管在另一个控件中时,通常不可能成为 DDE 服务器吗?

感谢您的回复

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心小果奶 2025-01-04 04:39:19

事实证明,这是不可能的。在托管模式下,主机应用程序需要是 DDE 服务器。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文