Need help in Query interface

Posted on 2008-11-07
Last Modified: 2013-11-17
I need help in query interface like i am getting  com pointer through a function and i need to extract the data  and  put in the required type.

 CComPtr<IModelDoc2>      swDrawing            = NULL;                CComPtr<IDrawingDoc>      swDraw            = NULL;      object

hRetStatus      = swApp->get_IActiveDoc2 (&swDrawing);
now im getting value in swdrawing but i need the same doc info value to be stored in swdraw also but i cannot call the function again because drawingdoc doesnt support it so im doing query interface i want to know whether what i have done is right or wrong

hRetStatus = swDrawing->QueryInterface(__uuidof(IDrawingDoc), reinterpret_cast<void**> (&swDraw));
Question by:Sohela
    LVL 3

    Accepted Solution

    looks fine,
    you can also use,
    hRetStatus = swDrawing.QueryInterface<IDrawingDoc> ( &swDraw );
    LVL 11

    Assisted Solution

    It is recommended that you use the IID_PPV_ARGS macro, defined in Objbase.h, to package the riid and ppv parameters. This macro provides the correct IID based on the interface pointed to by the value in ppv, which eliminates the possibility of a coding error.

    hRetStatus = swDrawing->QueryInterface(IID_PPV_ARGS(swDraw));

    Author Comment

    Thanks for the replies is it ok no if i call  drawingdoc functions on swdraw now swdraw pointer wont have a null value now no.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now