• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

Need help in Query interface

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));
2 Solutions
looks fine,
you can also use,
hRetStatus = swDrawing.QueryInterface<IDrawingDoc> ( &swDraw );
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));
SohelaAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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