Solved

How to pass a Visual Basic Database to MFC?

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 70
Having a different time zone on your task bar 3 78
Thin secure Windows 10 5 107
PL SQL Developer 7 73
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…

749 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