Solved

VB Migration

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now