Solved

Importing C++ classes in Visual Basic

Posted on 1997-05-20
5
253 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 100 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

690 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