社区成员已将此帖子与类似的问题关联:
hr = m_pDWriteFactory->CreateTextFormat这个地方就报错显示说是this 是 nullptr是怎么回事?如何解决?

只有审查方才能编辑此内容。

代码执行到Return Hr 这个地方就报错显示说是this 是 nullptr是怎么回事?如何解决?

SUN 20 信誉分
2024-11-08T09:03:26.79+00:00

HRESULT CMainWindow::CreateDeviceIndependentResources(HWND hwnd)

{

Static const WCHAR msc_fontName[] = L"Verdana";

static const FLOAT msc_fontSize = 50;

HRESULT hr;

ID2D1GeometrySink *pSink = NULL;

// Create a Direct2D factory.

hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

if (SUCCEEDED(hr))

{

    // Create WIC factory.

    hr = CoCreateInstance(

        CLSID_WICImagingFactory,

        NULL,

        CLSCTX_INPROC_SERVER,

        IID_IWICImagingFactory,

        reinterpret_cast<void **>(&m_pWICFactory)

        );

}

if (SUCCEEDED(hr))

{

    // Create a DirectWrite factory.

    hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,__uuidof(IDWriteFactory),reinterpret_cast<IUnknown**>(&m_pDWriteFactory));

}



if (SUCCEEDED(hr))

{

    // Create a DirectWrite text format object.

    hr = m_pDWriteFactory->CreateTextFormat(msc_fontName,NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,DWRITE_FONT_STRETCH_NORMAL,            

        msc_fontSize,

        L"", //locale

        &m_pTextFormat

        );

}

if (SUCCEEDED(hr))

{

    // Center the text horizontally and vertically.

    m_pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);

    m_pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);

    // Create a path geometry.

    hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometry);

}

if (SUCCEEDED(hr))

{

    // Use the geometry sink to write to the path geometry.

    hr = m_pPathGeometry->Open(&pSink);

}

if (SUCCEEDED(hr))

{

    pSink->SetFillMode(D2D1_FILL_MODE_ALTERNATE);

    pSink->BeginFigure(

        D2D1::Point2F(0, 0),

        D2D1_FIGURE_BEGIN_FILLED

        );

    pSink->AddLine(D2D1::Point2F(200, 0));

    pSink->AddBezier(

        D2D1::BezierSegment(

            D2D1::Point2F(150, 50),

            D2D1::Point2F(150, 150),

            D2D1::Point2F(200, 200))

        );

    pSink->AddLine(D2D1::Point2F(0, 200));

    pSink->AddBezier(

        D2D1::BezierSegment(

            D2D1::Point2F(50, 150),

            D2D1::Point2F(50, 50),

            D2D1::Point2F(0, 0))

        );

    pSink->EndFigure(D2D1_FIGURE_END_CLOSED);

    hr = pSink->Close();

}

SafeRelease(&pSink);

return hr;

}

C++
C++
一种通用的高级编程语言,作为 C 编程语言的扩展而创建,除了用于低级别内存操作的功能外,还具有面向对象、泛型和功能性等特点。
146 个问题
0 个注释 无注释
{count} 票