Like Tree1Likes
  • 1 Post By Troy Curless

Unresolved Symbol Error in EZFontCreate, Petzold

This is a discussion on Unresolved Symbol Error in EZFontCreate, Petzold within the Windows Programming forums, part of the Platform Specific Boards category; I'm refrencing Charles Petzolds book on win32 programming yet In the code I have slightly modified with a win32 template ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    11

    Unresolved Symbol Error in EZFontCreate, Petzold

    I'm refrencing Charles Petzolds book on win32 programming yet In the code I have slightly modified with a win32 template project I'm getting the following error.


    Code:
    1>FONTROT.obj : error LNK2019: unresolved external symbol "struct HFONT__ * __cdecl EzCreateFont(struct HDC__ *,wchar_t *,int,int,int,int)" (?EzCreateFont@@YAPAUHFONT__@@PAUHDC__@@PA_WHHHH@Z) referenced in function "void __cdecl PaintRoutine(struct HWND__ *,struct HDC__ *,int,int)" (?PaintRoutine@@YAXPAUHWND__@@PAUHDC__@@HH@Z)
    1>C:\Users\rip\Documents\Visual Studio 2012\Projects\BoustahedonCC++\Debug\BoustahedonCC++.exe : fatal error LNK1120: 1 unresolved externals
    I triple checked the signatures and types on the relevant functions and everything seems to match. I'm using the device context from the main window in the template code to call PaintRoutine which is from the fontrot program in petzolds book under Text and Fonts. I could post more code but do not know what to post.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I'll trust you on the types matching (I normally don't). The cdecl would seem to me to indicate that the function "EzCreateFont" should either be compiled as C code or be inside an "extern C" block if compiled as C++, so you should check how the file that contains the function was compiled.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    11
    Quote Originally Posted by tabstop View Post
    I'll trust you on the types matching (I normally don't). The cdecl would seem to me to indicate that the function "EzCreateFont" should either be compiled as C code or be inside an "extern C" block if compiled as C++, so you should check how the file that contains the function was compiled.

    I checked the code, the cpp that contains the function is being compiled with preprocessor 32 functionality. Over the entire project this might not be true. I doubt the their is a linking error with the includes but it is possible, and it could have to due with the fact that the project was not started as a win 32 project rather a win 32 project was included into an empty project in which a win 32 template was include (thus the setteings may not have crossed over). Perhaps you could guide me in checking the include theory as I forgot exactly ifndef in relationship to multiple header files and cpp files in a project. Thanks for replying and taking the time to read this post.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Do the signatures match?
    ie EzCreateFont declared as HFONT EzCreateFont(HDC *,wchar_t *,int,int,int,int) (name and params must be the same, wchar_t == WCHAR)

    If you right click on EzCreateFont in the paint handler in Visual Studio can you go to definition? (if not check you have linked it correctly)

    You could try some of the fixes here;
    Linker Tools Error LNK2019
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    11
    Quote Originally Posted by novacain View Post
    Do the signatures match?
    ie EzCreateFont declared as HFONT EzCreateFont(HDC *,wchar_t *,int,int,int,int) (name and params must be the same, wchar_t == WCHAR)

    If you right click on EzCreateFont in the paint handler in Visual Studio can you go to definition? (if not check you have linked it correctly)

    You could try some of the fixes here;
    Linker Tools Error LNK2019

    The signatures match, I believe here is the code of the paint routine
    Code:
    TCHAR szAppName [] = TEXT ("FontRot") ;
    //TCHAR szTitle [] = TEXT ("FontRot: Rotated Fonts") ;
    void PaintRoutine (HWND hwnd, HDC hdc, int cxArea, int cyArea)
    {
    	static TCHAR szString [] = TEXT (" Rotation") ;
    	HFONT hFont ;
    	int i ;
    	LOGFONT lf ;
    
    
    	hFont = EzCreateFont(hdc, TEXT ("Times New Roman"), 540, 0, 0, 1) ;
    	GetObject (hFont, sizeof (LOGFONT), &lf) ;
    	DeleteObject (hFont) ;
    	SetBkMode (hdc, TRANSPARENT) ;
    	SetTextAlign (hdc, TA_BASELINE) ;
    	SetViewportOrgEx (hdc, cxArea / 2, cyArea / 2, NULL) ;
    	for (i = 0 ; i < 12 ; i ++)
    	{
    		lf. lfEscapement = lf. lfOrientation = i * 300 ;
    		SelectObject (hdc, CreateFontIndirect (&lf)) ;
    
    
    		TextOut (hdc, 0, 0, szString, lstrlen (szString)) ;
    
    
    		DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
    	}
    }
    Here is the code of Ezfont
    Code:
    #include<Windows.h>#include"EZFONT.h"
    #include <math.h>
    
    
    
    
    HFONT  EZCreateFont(HDC hdc, WCHAR * szFaceName, int iDeciPtHeight, int iDeciPtWidth, int iAttributes, int fLogRes)
    	{
    		FLOAT	cxDpi, cyDpi ;
    		HFONT   hFont ;
    		LOGFONT lf;
    		POINT pt;
    		TEXTMETRIC tm;
    ...
    Here is where I call the paint routine:
    Code:
     HDC hdc;   hdc=GetDC(hWnd);
       PaintRoutine (hWnd,hdc, 40, 40);

    I looked up the link error tried compiling with clr support and and tried changing the debug mode as described still no success the errors described on msn where fairly cryptic even when explained but the ones I understood I looked at and couldn't find anything wrong, it's probably something obvious like wchar or statically passing a tchar with the Text routine but I am still stumped. Thanks for your patients your dealing with a pretty inexperienced coder here.

  6. #6
    Registered User
    Join Date
    Sep 2011
    Posts
    11
    I fixed the problem doh EzFontCreate was misscapitolized as EZFontCreate in the definition thanks it was a learning experience!
    stahta01 likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error LNK2019: unresolved external symbol
    By Cannibalope in forum C++ Programming
    Replies: 3
    Last Post: 12-06-2012, 09:35 PM
  2. error LNK2001: unresolved external symbol
    By kandas.soft in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2011, 07:51 AM
  3. Help with: error LNK2019: unresolved external symbol
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2010, 07:26 AM
  4. Replies: 3
    Last Post: 10-02-2007, 10:12 PM
  5. Error: unresolved external symbol
    By amirahasanen1 in forum C++ Programming
    Replies: 5
    Last Post: 10-07-2005, 10:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21