Reputation: 884
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.
Upvotes: 1
Views: 1545
Reputation: 10418
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.
Upvotes: 2
Reputation: 1477
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
Upvotes: 0