By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Creating objects (by assignment) in VB6

P: n/a
I know this is a VB.Net ng. But hopefully, someone remembers some
classic (VB6) coding - besides I've not had any response when I posted
this to the VB6 specific ng.

I wrote a C++ librray that I want to use in VB6. I have exported a C API
(via a win32 DLL) that may be used in VB6 using the 'Declare Function'
syntax.

However, I need to group related functions together (in VB6), by
wrapping them together in a VB6 class.

Assuming CreateNewObject is an exposed C function that returns a pointer
to a C++ object is declared in VB6 as follows:

Declare function CreateNewObject lib "mylib" () as long

Using the plain API (without wrapping the C++ objects in a VB6 class), I
would have code that looks like this :

dim lngPtr as long
lngPtr = CreateNewObject() 'calls Dll function
With the exposed C functions wrapped up in VB6 classes, the code looks
something like this:

dim objVBWrapper as MyVBWrapperClass

// which of these statements are correct?
objVBWrapper = CreateNewObject() //OR
Set objVBWrapper = CreateNewObject()

The key difference here is that I am creating the object by assignment.
Since there is no explicit copy constructor in VB6 I'm not sure how this
may be implemented. Ideas please ...
Jun 24 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Bartholomew Simpson" <12**********@terrace.comschrieb
I know this is a VB.Net ng. But hopefully, someone remembers some
classic (VB6) coding - besides I've not had any response when I
posted this to the VB6 specific ng.

I wrote a C++ librray that I want to use in VB6. I have exported a C
API (via a win32 DLL) that may be used in VB6 using the 'Declare
Function' syntax.

However, I need to group related functions together (in VB6), by
wrapping them together in a VB6 class.

Assuming CreateNewObject is an exposed C function that returns a
pointer to a C++ object is declared in VB6 as follows:

Declare function CreateNewObject lib "mylib" () as long

Using the plain API (without wrapping the C++ objects in a VB6
class), I would have code that looks like this :

dim lngPtr as long
lngPtr = CreateNewObject() 'calls Dll function
With the exposed C functions wrapped up in VB6 classes, the code
looks something like this:

dim objVBWrapper as MyVBWrapperClass

// which of these statements are correct?
objVBWrapper = CreateNewObject() //OR
Set objVBWrapper = CreateNewObject()

The key difference here is that I am creating the object by
assignment. Since there is no explicit copy constructor in VB6 I'm
not sure how this may be implemented. Ideas please ...
VB6 objects are COM/ActiveX objects. The C++ objects are (normally) not, so
you can not assign a pointer to a C++ object to a VB object variable. The
infrastructure is different.

The two options you have is either write COM objects in C++, or export
native functions from C++ and wrap them into a VB6 class. You did export
functions, but what you are trying here is using the members of a C++
object. There is no built-in way to access a C++ object from VB6.
Armin

Jun 24 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.