在 Windows 窗体应用程序中混合使用 VB5 和 C#
我想向我的应用程序添加一个窗口。是否可以使用 C#“扩展”旧的 vb5 项目?
它容易做和维护吗?这是一个好的做法吗?如果没有,还有哪些替代方案?
I'd like to add a window to my application. Is it possible to "extend" an old vb5 project using C#?
Is it easy to do and maintain and is it a good practice ? If not, what are the alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要做的事情很困难,因为你需要架起两个世界的桥梁。
VB5 和 C# 都可以创建和使用 COM 对象,您可以使用它从 .net 调用 VB5 代码或从 VB5 调用 .net 代码。
您还可以在.net 中创建和使用Active X 控件,因此如果需要,您可以以相同的形式混合VB5 和C#。
另一种选择是让两个独立的应用程序与同一个数据库通信并使用 COM(或 SendMessage)相互打开表单。
您需要深入了解 .net 才能使 COM 正常工作,但是,除非您花一些时间在 .NET 中工作,否则您不太可能有这种了解。
市场上也有一些工具声称将 VB5 代码转换为 VB.NET,但我对其中任何一个都没有厌倦。
What you are trying to do is hard as you need to bridge the two worlds.
Both VB5 and C# can create and consume COM object you can use this to call VB5 code from .net or .net code from VB5.
You can also create and use Active X controls in .net, so you can mix VB5 and C# in the same form if you must.
Another option is to have two separate applications that talk to the same database and used COM (or SendMessage) to open forms in each other.
You need a deep understand of .net to get COM working well, however you are not likely to have that understanding until you have spent some time working in .NET.
There are also tools on the market that claim to convert VB5 code into VB.NET, however I have not tired any of them.
编辑
我最初误读了这个问题,以为你在问 VB.NET。
您能做的最好的事情就是将 C# 公开为从 VB5 调用的 COM 对象。您只需要确保支持
IDispatch
。edit
I misread the question initially, thinking you were asking about VB.NET.
The best you can do is expose your C# as a COM object that you call from VB5. You just need to make sure you support
IDispatch
.