Solved

Importing C++ classes in Visual Basic

Posted on 1997-05-20
5
211 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now