Implementing smart interface pointers in MFC application

Dear all,
How to implement smart interface pointers for standard interfaces ( such as ISpecifyPropertyPages, IViewObjectEx, etc. ) in a MFC application ( VC++ 6.0)?
Any information will be very much helpful.
Thanking you
Rashmin
RashminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abdijCommented:
Sorry i did not get you.
Can you please elaborate what smartness you want to incorporate? What is it that you exactly want to do?

Thanx
0
RashminAuthor Commented:

Ok abdij, let me put it very clearly.
I wish to implement interfaces as they have been implemented in the "ActiveX Control Test Container" application shipped with VC++ 6.0 ( sample tstcon )
In that application while using an interface 'ISpecifyPropertyPages' ( the interface used for accessing property pages of an control inserted in a container ) , they have used a smart pointer ISpecifyPropertyPagesPtr, using which a lot of hassles like calling CoCreateInstance, QI'ing the interface is saved. Instead we can directly declare a variable name like
ISpecifyPropertyPagesPtr pSpecify;
and start using
pSpecify->Func1(),pSpecify->Func2()etc.
I wish to achieve this same functionality in my application.
Thanx
Rashmin

0
abancroftCommented:
Use #import to convert the type library into a bunch of C++ classes.

These C++ classes include the smart pointer funcitonality you describe.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

abancroftCommented:
Of course, you need need a type library/EXE/DLL/OCX that exposes the interfaces you are interested in....
0
RashminAuthor Commented:
Thanx abancroft.
I've to use #import is true. But what i do not understand is how do i get a
 TLB/EXE/OCX/DLL for standard interfaces like the ones i asked above or put it other way how do i know which TLB/OCX/EXE/DLL exposes standard interfaces?

0
RashminAuthor Commented:
Hi
I have found the solution for the problem.
Actually, it is just a simple inclusion of a file.
comdef.h defines all the smart pointers for standard OLE interfaces.
By including this file in the project access to smart pointers is possible.
Thanking you for the help extended
Sincerely
Rashmin
0
gvgCommented:
Hi,
There is an other good way to do this
include <atlbase.h>

Now you can define smartpointers as this
CComPtr< ISpecifyPropertyPages > ISpecifyPropertyPagesPtr

or

CComQIPtr< ISpecifyPropertyPages > ISpecifyPropertyPagesQIPtr

The diffrance between those 2 is that you can do a auto QI with the later one.  for example

CComPtr< IUnknown > pUnk;
ISpecifyPropertyPageQIPtr pPage;

pUnk.CoCreateInstance( __uuidof( BLA ) );
pPage = pUnk;

And pPage will do a auto QI.

Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RashminAuthor Commented:
Thanx gvg. Even that is a nice solution. I think for ATL projects people usually follow the way you suggested, right?
I am winding up this question now
Thanx again
Rashmin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.