?
Solved

Importing C++ classes in Visual Basic

Posted on 1997-05-20
5
Medium Priority
?
261 Views
Last Modified: 2013-11-25
Is it possible to import a class exported from a Visual C++ DLL into Visual Basic (either 4.0 or 5.0)?  If so how is this done?
0
Comment
Question by:berven
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:berven
ID: 1426423
Edited text of question
0
 
LVL 3

Accepted Solution

by:
rmichels earned 200 total points
ID: 1426424
It is not possible to import a C++ class into VB and use it as a class. I offer up two suggestions on how to use C++ classes in VB.  

1) Implement the C++ class as an activeX object.

2) Write straight 'C' wrappers around the C++ classes.  Have the C funtions return a pointer (just a long) to the C++ classes managed by the C routines.  That was your VB can at least have a handle to a class, allowing multiple instances of classes to be created, but only the C funtion know how to interpret the handle.
0
 

Author Comment

by:berven
ID: 1426425
Thank you.  I was hoping I cound get away without having to wrap the class or implement it as an activeX object.
 
I read an article by Bruce McKinney called Extending Visual Basic with C++ DLL's (Microsoft Press April 1996) which led me to hope that this feature may be available in VB5.

Do you know if any other compilers (Borland Delphi or Borland Builder) can import C++ classes?
0
 
LVL 3

Expert Comment

by:rmichels
ID: 1426426
No feature has been added to VB5 that I know of regarding directly using classes from a C++ dll.  There are name mangling issues, stack frame issues (the this pointer).  I have never used Delphi, so I can't speak to that tool.

Creating an ActiveX control with Microsoft Visual C 5.0 is not that difficult.  Microsoft provides wizards that create a class that has all of the required guts for an activex control and you add your own functionality as needed.
0
 

Author Comment

by:berven
ID: 1426427
I will give the ActiveX control a try.  Thanks again.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question