Re: Two function prototypes in two separate .h files by SME
SME
Thu Dec 06 10:41:01 PST 2007
Thanks a lot. You guys have been of great help, as usual.
Using only MFC functions and passing pDC->m_hDC, as indicated by you guys
got me through.
As I mentionend in my post, I am into C++ only recently and still goting
through those exercises. But got something in hand to deliver. Though the
issue I posted here doesn't belong to GDI, all this I am using to decode an
EMF file - that is GDI work.
It may be recalled that most of us have to do things without first learning
it. There is no time in the industry. We have to learn as we go. However the
changes in the software industry are so fast, before we master onething, it
becomes obsolete.
Thanks once again to all.
ThanQ...
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:2oagl3dcc2g9d69h14vc9gsup0p2piqlbl@4ax.com...
> On Thu, 6 Dec 2007 11:16:45 -0500, "SME" <smelchuri@hotmail.com> wrote:
>
>>Hi,
>>
>>I am beginner to C++ but not to C, though I worked on C some 15 years ago.
>>So I need some help.
>>
>>I was implementing a call to EnumEnhMetaFile () function as per the docs
>>on
>>MSDN. Its prototype is:
>>
>>EnumEnhMetaFile (HDC hdc, ..., CONST RECT * lpRect);
>>
>>I have given only those args that are problematic. Before calling this
>>function, I coded as given below, taking a cue from an example on MSDN.
>>
>>HDC hDc;
>>hDC = GetDC (hWnd);
>>RECT * lpRect;
>>GetClientRect (hWnd, lpRect);
>>bOK = EnumEnhMetaFile (hDc, ..., lpRect);
>>
>>I get compilation errors as follows:
>>1. On GetDC, it says no args allowed. Also GetDC returns a "CDC *" and not
>>of HDC.
>>
>>2. On GetClientRect, it says it takes only one arg. If I use
>>"GetClientRect
>>(lpRect)", it compiles but crashes on running.
>
> This is because you're using MFC, your code exists inside a member
> function
> belonging to a class derived from CWnd, and CWnd has member functions with
> those names.
>
>>When I try to go to definitions, they point to the prototypes in
>>"afxwin.h"
>>and not to that in "winuser.h".
>>
>>My queries are:
>>1. How can I force the prototype in winuser.h rather than that in
>>afxwin.h?
>
> Use the scope resolution operator to make the compiler look in the global
> namespace, i.e. ::GetDC and ::GetClientRect. That said, as you are writing
> an MFC app, normally you should be using the MFC functions.
>
>>2. If that is not desirable or not possible, can I cast "CDC *" to "HDC"
>>so
>
> No, that cast will not work. However, CDC exposes the HDC as m_hDC and
> also
> through the function GetSafeHDC.
>
>>that my code will be as:
>>
>>CDC * pDc;
>>pDC = GetDC ( );
>>RECT * lpRect = 0;
>>bOK = EnumEnhMetaFile (pDc, ..., lpRect);
>
> Replace pDC with pDC->GetSafeHDC(), and you should be OK. You should also
> see if MFC defines the function in terms of CWnd. For that matter, would
> the MFC CMetaFileDC class simplify this even further?
>
>>3. Which is the forum for discussing GDI issues?
>
> Probably microsoft.public.win32.programmer.gdi.
>
> --
> Doug Harrison
> Visual C++ MVP