如何调用 C++ Visual Basic 的构造函数
我在 Visual Basic 代码中调用 C++ 构造函数时遇到问题。 DLL 已正确导入,但这一行特别给我带来麻烦:
Dim myobj As New MyObject("param1", "param2", "param3")
以及相应的 C++ 构造函数:
MyObject::MyObject(System::String ^ p1, System::String ^ p2, System::String ^ p3)
有什么建议吗?
I'm having trouble calling a C++ constructor in my Visual Basic code. The DLL has been imported correctly but this line in particular is giving me trouble:
Dim myobj As New MyObject("param1", "param2", "param3")
And the corresponding C++ constructor:
MyObject::MyObject(System::String ^ p1, System::String ^ p2, System::String ^ p3)
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能。这种方式根本不支持。
最简单的方法是将构造函数转换为函数(例如
Initialize()
)。You can't. It's simply not supported this way.
The easiest way of doing it is to just convert the constructor into a function (eg
Initialize()
).你不能 - 该类将使用默认构造函数实例化。如果您需要参数化构造,您有两个选择 - 要么向类添加“初始化”参数化方法,要么添加带有“用此参数实例化第一个类”方法的工厂类。
You can't - the class will be instantiated with a default constructor. If you need parameterized construction you have two options - either add an "initialize" parameterized method to the class or add a factory class with an "instantiate the first class with this parameters" method.
使用抽象接口并创建工厂来生成对象。它还将保持代码和 dll 之间的抽象。阅读这篇文章
http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx
Use abstract interfaces and make factory to generate objects. Also it will keep the abstraction between your code and dll. Read this article
http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx