Solved

How to pass a Visual Basic Database to MFC?

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference between String.subString() and String.subSequence() 6 199
post4 challenge 28 100
canBalance challenge 34 85
Need more details 5 151
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

773 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