Solved

How to pass a Visual Basic Database to MFC?

Posted on 1998-06-10
4
219 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

708 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

16 Experts available now in Live!

Get 1:1 Help Now