🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.multimedia
Article #111

D3DXCreateFont

#111
From: Jonathan Benedicto
Date: Thu, 31 Mar 2005 02:42
60 lines
2539 bytes
I'm using dx 9 to build a 3d app.

I've been trying to use D3DXCreateFont to create a D3DDXFont so that I 
can draw some info to the back buffer.

I create the D3DDXFont in a method like this :

HRESULT __fastcall TMForm::CreateD3DXFont(LPD3DXFONT* ppd3dxFont, 
AnsiString pstrFont, DWORD dwSize)
{
        HRESULT hr;
        LPD3DXFONT pd3dxFontNew = NULL;
        HDC hDC;
        INT nHeight;
        HFONT hFont;

        hDC = GetDC( NULL );
        nHeight = -MulDiv(dwSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
        ReleaseDC(NULL, hDC);

        hFont = CreateFont(nHeight, 0, 0, 0, FW_DONTCARE, false, 
false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, 
pstrFont.c_str());
        if(hFont == NULL)
                return E_FAIL;

        try{
                hr = D3DXCreateFont(g_pd3dDevice, hFont, 
&pd3dxFontNew);
        }catch(Exception& E){
                hr = E_FAIL;
                Log->Add("Exception thrown while creating font.");
        }catch(...){
                hr = E_FAIL;
                Log->Add("Exception thrown while creating font.");
        }
        DeleteObject(hFont);

        if(SUCCEEDED(hr))
                *ppd3dxFont = pd3dxFontNew;

        return hr;
}

And call the method like this :

// Create a font for statistics and help output
hr = CreateD3DXFont(&g_pd3dxFont, "Arial", 14);
if(FAILED(hr)){
    Log->Add("Can't create font.");
    throw Exception("Can't create font.");
}

However, the call to D3DXCreateFont always throws a EAccessViolation. 
Please can someone help me to find out what I've done wrong.

-- 
Jonathan
 
Technical Details
Message-ID: <424b637f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,a1d69accdcc5e7c2,start
X-Google-Attributes: gid10d0fc,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jonathan Benedicto" <incorrect@no.server>
Newsgroups: borland.public.cppbuilder.multimedia
Subject: D3DXCreateFont
Date: Wed, 30 Mar 2005 21:42:09 -0500
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
NNTP-Posting-Host: 64.231.17.125
Message-ID: <424b637f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1112236927 64.231.17.125 (30 Mar 2005 18:42:07 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail