VBA面向对象编程
这个问题是上一个问题的扩展: 在 VBA 中返回一个对象
现在,我我想知道如何在VBA中声明和初始化该对象。看起来我会这样做:
Declare Function ConnectMe Lib "C:\Windows\System32\cm.dll" (ByVal Arg1 As String) As ConnectMe
Declare Function login Lib "C:\Windows\System32\cm.dll" (ByVal Arg1 As String, ByVal Arg2 As String) As Boolean
然后,在这一行下面,我可以使用这段代码:
dim cm as new ConnectMe
cm.ConnectMe("216.239.51.99")
cm.login("username","password")
但是,当我这样做时,它给了我一个“用户定义的类型未定义”错误。如何正确声明此 C++ 类,以便可以在 VBA 中创建和使用实例?
谢谢。
This question is an extension of a previous question: Return an object in VBA
Now, I'd like to know how to declare and initialize the object in VBA. It seems like I'd do it like so:
Declare Function ConnectMe Lib "C:\Windows\System32\cm.dll" (ByVal Arg1 As String) As ConnectMe
Declare Function login Lib "C:\Windows\System32\cm.dll" (ByVal Arg1 As String, ByVal Arg2 As String) As Boolean
Then, below this line, I could use this code:
dim cm as new ConnectMe
cm.ConnectMe("216.239.51.99")
cm.login("username","password")
However, when I do this, it gives me a "User-defined type not defined" error. How can I declare this C++ class appropriately so that I can create and use an instance in VBA?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码永远不会像现在这样工作。如果您想在 Windows 下用 C++ 创建一个类,并在非 C++ 的任何其他编程语言(例如 VB)中使用它,“正常”方法是创建一个 COM 类 或 ActiveX 控件(如果需要)绘制图形。
您还可以找到这个答案 很有帮助。
This code is never going to work as it is. If you want to create a class in C++ under Windows and use it in any other programming language that is not C++, (VB for example) the "normal" approach is to create a COM class or an ActiveX control if you need to draw graphics.
You may also find this answer in SO helpful.
我再次在这里:D
要将此代码与您的函数一起使用,请使用:
i here again :D
To use this code with your function use: