从非托管 C++ 启动 C# 对话框 MFC 活动 x dll
我被告知用 C# 编写一个对话框,该对话框必须从非托管 c++ dll 实例化。 我们在代码中的其他位置执行此操作,只需将托管 C++ 类添加到 C++ 项目,然后从托管 C++ 类调用 C# dll。 然而我发现这对我来说不起作用,因为我必须这样做。 我认为因为c++ dll是一个MFCActiveX项目。 一旦我在此项目中的任何文件上设置 clr,它将不再正确注册。 当我尝试注册它时,我收到三个错误,然后收到一条它已注册的消息。 但是,当我尝试使用它时,出现 0x80040111“ClassFactory 无法提供请求的类”错误。 如果有人知道这里的问题是什么,我将不胜感激。 我要么需要能够完成这个(首选),要么证明这是不可能的。
谢谢
I've been told to write a dialog in C# which must be instantiated from an unmanaged c++ dll. We do this in other places in our code by simply adding a managed c++ class to the C++ project, then calling the C# dll from the managed c++ class. However I'm finding that doesn't work for me from where I have to do it. I think because the c++ dll is an MFCActiveX project. As soon as i set the clr on any file in this project, it will no longer register correctly. When i attempt to register it, i get three errors, then a message that it registered. However when i try to use it i get a 0x80040111 "ClassFactory cannot supply requested class" error.
If anyone has any idea what the problem is here i would greatly appreciate it. I either need to be able to accomplish this (preferred) or prove that it's not possible.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看不出 MFCActiveX 项目如何阻止您以这种方式创建 C# 类。 除非它根本不允许添加托管类。
如果您无法使托管 C++ 类技巧发挥作用,另一个选择是使用 COM。 可以在 C# 项目中将某种工厂注册为 COM 对象。 假设给它以下接口,
您还必须创建一个支持类。 但随后您可以注册托管程序集并使用 COM 来访问它。
I can't see how a MFCActiveX project would prevent you from creating the C# class in this way. Unless it simply does not allow for a managed class to be added.
If you can't get the managed C++ class trick to work, another option is to use COM. It's possible to register a factory of sorts in the C# project as a COM object. Say give it the following interface
You'd also have to create a backing class as well. But then you could register the managed assembly and use COM to access it.
您现在必须使用“regasm”而不是“regsvr32”注册它。
You must now register it with "regasm" instead of "regsvr32".