VBA面向对象编程

发布于 2024-12-07 21:54:18 字数 622 浏览 0 评论 0原文

这个问题是上一个问题的扩展: 在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老子叫无熙 2024-12-14 21:54:18

这段代码永远不会像现在这样工作。如果您想在 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.

白芷 2024-12-14 21:54:18

我再次在这里:D

要将此代码与您的函数一起使用,请使用:

Dim cm as Object

set cm = ConnectMe("parameter")

if cm.login("username","password") then 
     msgbox "Connect!",vbinformation
else
     msgbox "not connect!",vbinformation
end if

i here again :D

To use this code with your function use:

Dim cm as Object

set cm = ConnectMe("parameter")

if cm.login("username","password") then 
     msgbox "Connect!",vbinformation
else
     msgbox "not connect!",vbinformation
end if
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文