DDE 服务器在托管模式下未建立连接
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,这是不可能的。在托管模式下,主机应用程序需要是 DDE 服务器。
It turned out, that this is not possible. In hosted mode, the host application needs to be the DDE server instead.