Solved

How to pass a Visual Basic Database to MFC?

Posted on 1998-06-10
4
248 Views
Last Modified: 2013-11-25
I want to pass a database from Visual Basic 4.0 to MFC (using OCX control by VC++ 4.2). What is the type of argument to pass? I have tried LPUNKNOWN FAR * and LPUNKNOWN but not successful, I guess the question is "How to pass an Object from VB to MFC VC++?"
0
Comment
Question by:hshliang
  • 2
4 Comments
 
LVL 4

Expert Comment

by:vvk
ID: 1317847
Simply add OLE control to project (Project must have OLE control container enabled) by selecting in menu Insert->Component. Insert instance of control to dialog. Add member variable to class. Now you can use common C++ methods to access this class.
More Information you can get from VC Books On-Line (MSDEV)
Topic "Visual C++/MFC 4.2//Programming with MFC:Encyclopedia//OLE Control Container"
0
 
LVL 2

Accepted Solution

by:
rayb earned 100 total points
ID: 1317848
I'll make the assumption that you are using either DAO or ADO
on the visual basic side.  To pass either of these to a VC OCX,
prototype your function in VC to receive a VARIANT.  Behind the scenes, VB will pack the database object into the
VARIANT's pdispVal member automatically.  This is the interface
that you will receive in your VC OCX.  From there, simply treat it
as you would any other COM interface, however, don't call
pdispVal->Release() when finished or VB will complain loudly.
0
 

Author Comment

by:hshliang
ID: 1317849
I like the suggestion of using VARIANT, I will try that method. I don't quite understand the second proposal of using OLE container. Thank you guys.
0
 

Author Comment

by:hshliang
ID: 1317850
Dear rayb,
I have tried your way, it is the same as passing as LPUNKNOWN, the database is passed as IDISPATCH (or pdispVal in VARIANT) but please tell me how do I convert it to a CDaoDatabase pointer so I can use it as any C++ object? I tried to cast it to CDaoDatabase * but using it case an ACCESS VIOLATION error. (e.g. ((CDaoDatabase *)var.pdispVal)->GetName(); )

Please help.Thank you.
Henry
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Poor Man's .NET Framework Certification 2 60
Sed question 2 101
Using MS Code on my Mac 6 68
Please explain the parts of these 2 LINQ expressions 3 53
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…

861 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