Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to pass a Visual Basic Database to MFC?

Posted on 1998-06-10
4
Medium Priority
?
264 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
[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
  • 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 300 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…

610 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