将 CreateDispatch 调用所调用的 VB6 DLL 替换为 C# 等效项
现有的 Visual C++ 应用程序进行以下调用;
BOOL bRet = pMyClass.CreateDispatch("BlahBlah.MyClass");
if ( !bRet )
{
// Error handling snipped
}
else
{
pMyClass.MyMethod();
pMyClass.ReleaseDispatch();
}
pMyClass 是一个显然是由 ClassWizard 自动生成的类,它继承自 COleDispatchDriver。
它所引用的实际 DLL 是 VB6 的,并且正在将其迁移到 C#,作为总体上摆脱 VB 的努力的一部分。
我的问题是...我需要做些什么特殊的事情来确保 C# 程序集能够以与原始 VB6 模块相同的方式工作吗?目前,C# 看起来像这样;
[ComVisible(true)]
[ProgId("BlahBlah.MyClass")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class MyClass
{
...
public void MyMethod()
{
...
}
}
这足够了吗?在 MyClass 上设置公共字符串字段(代码中未显示)时是否有任何需要注意的问题?
请注意,我不是此代码的原始作者 - 它来自遗留系统,我只是进行迁移。
An existing Visual C++ application makes the following call;
BOOL bRet = pMyClass.CreateDispatch("BlahBlah.MyClass");
if ( !bRet )
{
// Error handling snipped
}
else
{
pMyClass.MyMethod();
pMyClass.ReleaseDispatch();
}
pMyClass is a class which was apparently auto-generated by ClassWizard, and it inherits from COleDispatchDriver.
The actual DLL to which it refers is a VB6 one, and this is being migrated to C# as part of an effort to move away from VB in general.
My question is... is there anything special I need to do to make sure that the C# assembly will work in the same way as the original VB6 module did? Currently, the C# looks like this;
[ComVisible(true)]
[ProgId("BlahBlah.MyClass")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class MyClass
{
...
public void MyMethod()
{
...
}
}
Is this sufficient? Are there any gotchas to be aware of when setting public string fields (not shown in code) on MyClass?
Note that I'm not the original author of this code - it's from a legacy system and I'm just doing the migration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CreateDispatch 调用使用后期绑定与 COM 服务器通信。类接口类型.AutoDispatch。使用 AutoDual 很好,还包括后期绑定支持。凭借显着的优势,有一天你可以让它变得更快。后期绑定并不便宜。
The CreateDispatch call uses late binding to talk to the COM server. ClassInterfaceType.AutoDispatch. Using AutoDual is fine, that also includes late binding support. With the significant advantage that you can make it a lot faster some day. Late binding isn't cheap.