Solved

VB Migration

Posted on 2000-05-04
2
229 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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