问题描述
上下文:
我正在使用一些旧的机器人软件,如果该软件实现了一些预定义的接口,则该软件可以从COM对象获取信息.由于此旧软件可以在Windows 2000上运行,因此我想使用DCOM来(避免)为Windows 2000编译某些东西.(我知道必须调用的程序可能需要工作,或者至少存在,在Windows 2000计算机上也是如此)
I'm working with some old robotics software which is able to get information from a COM object if it implements some predefined interfaces. Since this old software runs on Windows 2000, I want to use DCOM to (try to) avoid having to compile something for Windows 2000. (I am aware that the program that has to be called probably needs to work, or at least exist, on the Windows 2000 computer as well)
将通过DCOM调用另一台计算机,并将使用一组配置的步骤来处理图像.我希望GUI能够显示传入和传出的图像以及更改其执行步骤的能力.
The other computer will be called through DCOM and will process an image using a configured set of steps. I would like a GUI to show the incoming and outgoing images and the ability to change the steps it undertakes.
问题
图像处理器需要实现两个接口,但是Interface1和Form
一样包含Load
函数,但是都需要保持可访问性,因此我认为我不能使用new
关键字.因此,下面的代码将不起作用.
The image processor needs to implement two interfaces, but Interface1 contains a Load
function, as does the Form
, but both need to remain accessible so I don't think I can use the new
keyword. Therefore the code below will not work.
public class ServerForm : Form, Interface1, Interface2 { }
我可以这样分割他们:
public class ServerForm : Form { }
public class MyImageProcessor : Interface1, Interface2 { }
但是我仍然需要从MyImageProcessor类访问Form.我试图通过以下构造函数将Form传递给MyImageProcessor:
But I'll still need to access the Form from the MyImageProcessor class. I tried passing the Form to the MyImageProcessor through the constructor like this:
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ServerForm sv = new ServerForm();
MyImageProcessor mip = new MyImageProcessor(sv);
Application.Run(sv);
}
}
但是,当我使用regasm CSharpServer.exe /regfile:CSharpServer.reg
来检查将哪些项添加到注册表中时,只会显示ServerForm,而不会显示ImageProcessor.
But when I use regasm CSharpServer.exe /regfile:CSharpServer.reg
, to check which keys are added to the registry, only the ServerForm shows up and not the ImageProcessor.
我该如何解决这个问题?
How can I solve this problem?
推荐答案
此解决方案解决了上述两个问题:两个load
函数将保持可用状态,并且会生成正确的注册表项,但是我不这样做稍后会给COM带来任何问题. (可能会)
This solution fixes both of the problems stated above: Both load
functions will remain available and the correct registry keys are generated, but I don't if it will give any problems with COM later, yet. (It probably will)
我将其分为两类. ServerForm是从MyImageProcessor
的构造函数生成并运行的.
I have split it in two classes. The ServerForm is generated and run from the constructor of MyImageProcessor
.
public class MyImageProcessor : Interface1, Interface2{
private static ServerForm sv;
public MyImageProcessor () {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
sv = new ServerForm();
Application.Run(sv);
}
}
和
public class ServerForm : Form {
public ServerForm() {
InitializeComponent();
}
}
我想强调指出,这可以解决现在的问题,如果一切正常,我将尝试更新此帖子.
I would like to stress that this fixes the problems for now, if I get everything working I'll try to update this post.
这篇关于用GUI制造COM服务器的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!