EnumFontFamiliesEx() Crash while trying to get system fonts

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Hi All ! ,
I have an error when trying to get all the fonts from the system into A list Tool.
Before i start i must say I dont have a lot of experience in Visual C++ , Im transferring from C++ & C to Visual right now.
What im trying to do is to get the entire Windows fonts list to a List tool on my DLG.

here is the code for that :


int CALLBACK MyEnumFontProc(ENUMLOGFONTEX* lpelf, NEWTEXTMETRICEX lpntm, DWORD nFontType , long lParam)
{
<span style="white-space:pre CSolarBox01Dlg* pWnd = (CSolarBox01Dlg*)lParam;

<span style="white-space:pre if (pWnd)
<span style="white-space:pre {
<span style="white-space:pre pWnd->m_ctlFontList.AddString(lpelf->elfLogFont.lfFaceName);
<span style="white-space:pre TRACE("GOOD");
<span style="white-space:pre return 1;
<span style="white-space:pre }
<span style="white-space:pre return 0;
}

void CSolarBox01Dlg::FillFontList(void)
{

<span style="white-space:pre LOGFONT lf;

<span style="white-space:pre lf.lfCharSet = DEFAULT_CHARSET;

<span style="white-space:pre lf.lfFaceName[0] = NULL;

<span style="white-space:pre lf.lfPitchAndFamily = 0;

<span style="white-space:pre m_ctlFontList.ResetContent();
<span style="white-space:pre
<span style="white-space:pre m_ctlFontList.AddString(L"Test String");

<span style="white-space:pre CClientDC dc(this);

<span style="white-space:pre ::EnumFontFamiliesEx( (HDC) dc , &lf , (FONTENUMPROC)MyEnumFontProc
<span style="white-space:pre , (LPARAM)this , 0);
}
The error i get :
<br/>

Unhandled exception at 0x54281f9c (mfc100ud.dll) in SolarBox 0.1.exe: 0xC0000005: Access violation reading location 0x60cb573e.
<br/>

when i press break it stops on that line :
<br/>


_AFXWIN_INLINE int CListBox::AddString(LPCTSTR lpszItem)
when <span style="white-space:pre { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); }

<br/>

output window for this run :
<br/>


Warning: initial dialog data is out of range.
First-chance exception at 0x54281f9c (mfc100ud.dll) in SolarBox 0.1.exe: 0xC0000005: Access violation reading location 0x60cb573e.
Unhandled exception at 0x54281f9c (mfc100ud.dll) in SolarBox 0.1.exe: 0xC0000005: Access violation reading location 0x60cb573e.

<br/>

<br/>

<br/>



View the full article
 
Back
Top