Re: Two function prototypes in two separate .h files
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