
Creating Objects in VB from C++ DLL
[All of the following assumes VB5/6, not VB.Net. You should post to
a different group if your question applies to .Net.]
Quote:
> I can call functions on the DLL fine...i just need to create an object in VB
> of the class defined in the C++ DLL...
> I can call this funtion and get the value back fine...This funtion belongs
> to the CCustomerInfoRS Class, so that means the DLL is fine and
> working....And I can use it in VB
> Private Declare Function ReturnNumber Lib "..\ServerDLL.dll" () As Integer
I'm a little curious about how you're going about it that a member
function is called through Declare and works correctly. This would
need to be a static member (non-static members would not work right),
and even then I'm not sure how you export it undecorated.
Also, it's unlikely that Integer is the correct return type -- most
likely it should be Long, which corresponds to the C++ int type
(VB Integer == C++ short).
Quote:
> There is a class in the DLL called CCustomerInfoRS, and I need to create an
> object of that class in my vb app.
Then you must wrap that C++ class in COM. VB does not understand
vanilla C++ classes. I'd recommend using ATL, personally, but it can
also be done using
MFC or, if you're really {*filter*}ic, by hand with
no framework support.
You could either convert your C++ class into a COM class, or you could
forward from the COM implementation into the plain C++ implementation.
Also note that VB requires automation-compatible classes, which means
that all object parameters must be either automation-compatible
interfaces or dual interfaces and all other parameters must be things
which can be stuffed in a Variant. You should add the oleautomation
attribute to the IDL for the class if you don't make it a dual
interface.