anatta18
asked on
problems with #define STRICT
Hi;
I have been working my way through Charles Petzold's book Programming Windows95 ( using C and the SDK ).
In a program I am building I found it necessary to "#define STRICT" to make the compiler accept an array of windproc pointers. That worked fine, but code that previously compiled okay doesn't compile now.
The error message I get is:
MainProgram.obj : error LNK2001: unresolved external symbol "struct HFONT__ * __cdecl EzCreateFont(struct HDC__ *,char *,int,int,int,int)" (?EzCreateFont@@YAPAUHFONT __@@PAUHDC __@@PADHHH H@Z)
"Ezfont.h" & "Ezfont.cpp" ( originally named Ezfont.c ) is a file for selecting fonts in Win95 that Charles Petzold included in his book.
Is there a way I can still use "#define STRICT", still use Ezfont, and have everyone place nice?
The code for Ezfont is below:
*----------------------
EZFONT.H header file
----------------------*/
HFONT EzCreateFont (HDC hdc, char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes) ;
#define EZ_ATTR_BOLD 1
#define EZ_ATTR_ITALIC 2
#define EZ_ATTR_UNDERLINE 4
#define EZ_ATTR_STRIKEOUT 8
/*------------------------ ---------- -----
EZFONT.C -- Easy Font Creation
(c) Charles Petzold, 1996
-------------------------- ---------- ---*/
#include <windows.h>
#include <string.h>
#include <math.h>
#include "Ezfont.h"
HFONT EzCreateFont (HDC hdc, char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes)
{
FLOAT cxDpi, cyDpi ;
HFONT hFont ;
LOGFONT lf ;
POINT pt ;
TEXTMETRIC tm ;
SaveDC (hdc) ;
SetGraphicsMode (hdc, GM_ADVANCED) ;
ModifyWorldTransform (hdc, NULL, MWT_IDENTITY) ;
SetViewportOrgEx (hdc, 0, 0, NULL) ;
SetWindowOrgEx (hdc, 0, 0, NULL) ;
if (fLogRes)
{
cxDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSX) ;
cyDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSY) ;
}
else
{
cxDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, HORZRES) /
GetDeviceCaps (hdc, HORZSIZE)) ;
cyDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, VERTRES) /
GetDeviceCaps (hdc, VERTSIZE)) ;
}
pt.x = (int) (iDeciPtWidth * cxDpi / 72) ;
pt.y = (int) (iDeciPtHeight * cyDpi / 72) ;
DPtoLP (hdc, &pt, 1) ;
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;
lf.lfWidth = 0 ;
lf.lfEscapement = 0 ;
lf.lfOrientation = 0 ;
lf.lfWeight = iAttributes & EZ_ATTR_BOLD ? 700 : 0 ;
lf.lfItalic = iAttributes & EZ_ATTR_ITALIC ? 1 : 0 ;
lf.lfUnderline = iAttributes & EZ_ATTR_UNDERLINE ? 1 : 0 ;
lf.lfStrikeOut = iAttributes & EZ_ATTR_STRIKEOUT ? 1 : 0 ;
lf.lfCharSet = 0 ;
lf.lfOutPrecision = 0 ;
lf.lfClipPrecision = 0 ;
lf.lfQuality = 0 ;
lf.lfPitchAndFamily = 0 ;
strcpy (lf.lfFaceName, szFaceName) ;
hFont = CreateFontIndirect (&lf) ;
if (iDeciPtWidth != 0)
{
hFont = (HFONT) SelectObject (hdc, hFont) ;
GetTextMetrics (hdc, &tm) ;
DeleteObject (SelectObject (hdc, hFont)) ;
lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
hFont = CreateFontIndirect (&lf) ;
}
RestoreDC (hdc, -1) ;
return hFont ;
}
I have been working my way through Charles Petzold's book Programming Windows95 ( using C and the SDK ).
In a program I am building I found it necessary to "#define STRICT" to make the compiler accept an array of windproc pointers. That worked fine, but code that previously compiled okay doesn't compile now.
The error message I get is:
MainProgram.obj : error LNK2001: unresolved external symbol "struct HFONT__ * __cdecl EzCreateFont(struct HDC__ *,char *,int,int,int,int)" (?EzCreateFont@@YAPAUHFONT
"Ezfont.h" & "Ezfont.cpp" ( originally named Ezfont.c ) is a file for selecting fonts in Win95 that Charles Petzold included in his book.
Is there a way I can still use "#define STRICT", still use Ezfont, and have everyone place nice?
The code for Ezfont is below:
*----------------------
EZFONT.H header file
----------------------*/
HFONT EzCreateFont (HDC hdc, char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes) ;
#define EZ_ATTR_BOLD 1
#define EZ_ATTR_ITALIC 2
#define EZ_ATTR_UNDERLINE 4
#define EZ_ATTR_STRIKEOUT 8
/*------------------------
EZFONT.C -- Easy Font Creation
(c) Charles Petzold, 1996
--------------------------
#include <windows.h>
#include <string.h>
#include <math.h>
#include "Ezfont.h"
HFONT EzCreateFont (HDC hdc, char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes)
{
FLOAT cxDpi, cyDpi ;
HFONT hFont ;
LOGFONT lf ;
POINT pt ;
TEXTMETRIC tm ;
SaveDC (hdc) ;
SetGraphicsMode (hdc, GM_ADVANCED) ;
ModifyWorldTransform (hdc, NULL, MWT_IDENTITY) ;
SetViewportOrgEx (hdc, 0, 0, NULL) ;
SetWindowOrgEx (hdc, 0, 0, NULL) ;
if (fLogRes)
{
cxDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSX) ;
cyDpi = (FLOAT) GetDeviceCaps (hdc, LOGPIXELSY) ;
}
else
{
cxDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, HORZRES) /
GetDeviceCaps (hdc, HORZSIZE)) ;
cyDpi = (FLOAT) (25.4 * GetDeviceCaps (hdc, VERTRES) /
GetDeviceCaps (hdc, VERTSIZE)) ;
}
pt.x = (int) (iDeciPtWidth * cxDpi / 72) ;
pt.y = (int) (iDeciPtHeight * cyDpi / 72) ;
DPtoLP (hdc, &pt, 1) ;
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;
lf.lfWidth = 0 ;
lf.lfEscapement = 0 ;
lf.lfOrientation = 0 ;
lf.lfWeight = iAttributes & EZ_ATTR_BOLD ? 700 : 0 ;
lf.lfItalic = iAttributes & EZ_ATTR_ITALIC ? 1 : 0 ;
lf.lfUnderline = iAttributes & EZ_ATTR_UNDERLINE ? 1 : 0 ;
lf.lfStrikeOut = iAttributes & EZ_ATTR_STRIKEOUT ? 1 : 0 ;
lf.lfCharSet = 0 ;
lf.lfOutPrecision = 0 ;
lf.lfClipPrecision = 0 ;
lf.lfQuality = 0 ;
lf.lfPitchAndFamily = 0 ;
strcpy (lf.lfFaceName, szFaceName) ;
hFont = CreateFontIndirect (&lf) ;
if (iDeciPtWidth != 0)
{
hFont = (HFONT) SelectObject (hdc, hFont) ;
GetTextMetrics (hdc, &tm) ;
DeleteObject (SelectObject (hdc, hFont)) ;
lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
hFont = CreateFontIndirect (&lf) ;
}
RestoreDC (hdc, -1) ;
return hFont ;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.