windows - 在 Windows 窗体应用程序与控制台应用程序中注册 DDE 服务器

标签 windows winforms dde

我需要在 Windows 窗体和控制台应用程序中注册 DDE 服务器。我已经在 Windows 窗体应用程序的各个点尝试了注册码,但它似乎没有注册。我已经在 frmMain 和 Program.cs Main() 中试过了。

当我尝试访问 DDE 服务器时,我收到标准的无法连接消息:“MainForm_Load:客户端无法连接到“CRMIntegrator|myservice”。确保服务器应用程序正在运行并且它支持指定的服务名称和主题名称对。”

这是我的注册码:

public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            try
            {
                // Create a server that will register the service name 'myapp'.
                using (DdeServer server = new MyServer("CRMIntegrator"))
                {
                    // Register the service name.
                    server.Register();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

最佳答案

您在这里没有适本地使用 using 关键字。 Register() 调用后,服务器将立即处理掉。这确实使得它不太可能在 Load 事件运行时仍然存在。

使 server 变量成为表单类中的一个字段。在表单关闭之前不要处理它,在 OnFormClosed() 方法覆盖或 FormClosed 事件处理程序中执行此操作。

关于windows - 在 Windows 窗体应用程序与控制台应用程序中注册 DDE 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4922472/

相关文章:

winforms - 如何创建水印文本框

python - 如何连续收听DDE数据

excel - SAS DDE excel另存为无警告

excel - 从自定义应用程序获取数据到 EXcel

windows - 批量合并文件

windows - git 克隆卡在 "checking connectivity"

c# - 如何根据后面的输入添加更多的标签?

windows - 比较批处理脚本中的数字数组

windows - 在 NSIS 中导入注册表项时出错

C# Base64 字符串可以转换为图像,但不显示在 .rdlc 图像控件中