Return an object in VBA

2019-07-17 06:18发布

问题:

I've built a custom DLL which, for this example, has a function login. In C++ I use it by creating an object and then accessing the function through the object pointer, like so:

ConnectMe *cm = new ConnectMe("216.239.51.99");
cm->login("username", "password")

What I'd like to be able to do is use this code in Excel. I've created a DLL and have exported the appropriate functions. How can I do this in VBA? Does VBA support returning pointers to my own custom objects? This page (http://msdn.microsoft.com/en-us/library/sect4ck6.aspx) fails to specify what kinds of types can be returned from a function.

Thanks in advance.

回答1:

If your DLL is registered in machine, in tools/reference, set the check to.

After, in your code use

dim cm as new ConnectMe

cm.ConnectMe("216.239.51.99")

cm.login("username","password")


标签: c++ excel vba dll