Solved

VB Migration

Posted on 2000-05-04
2
220 Views
Last Modified: 2010-04-02
The problem: Using an ActiveX dll

In VB, in the references dialog y can select any registered dll such as 'Olemsg.dll'.
Then in any piece of code i can instantiate objects exposed in the library using a simple and cheap Dim statement e.g.:
Dim obj As MAPI.Recipient
'or
Set obj = CreateObject("MAPI.Recipient")


How do I do the same in C++? I'm using VC++ 6.0

Thanks
0
Comment
Question by:trillo
2 Comments
 
LVL 2

Expert Comment

by:vbk_bgm
ID: 2779921
You need to derive a class from the type library (View -> ClassWizard and Add new class from the type lib). Select the classes that you need for your app.
Then you could create object using CreateDispatch and delete using ReleaseDispatch
For instance, if you are creating for Excel Automation.
m_Excel.CreateDispatch(Excel.Application);
where mExcel is of type Application in this case.
0
 

Accepted Solution

by:
MUpchu777 earned 50 total points
ID: 2794932
If your talking about COM Objects (which is what I see in your example), the easiest solution is to use the #import statement.  The syntax is #import "<name of dll or tlb file here>".  There are a few other parameters, but that is the basic gist.  VC will wrap the COM object with smart pointer classes that handle referencing and dereferencing for you.  THis is a highly recommended way to work with COM Objects in VC.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

785 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