[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

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
0
Rashmin
Asked:
Rashmin
1 Solution
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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
 
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now