访问Gdiplus :: PrivateFontCollection.AddMemoryFont时出现访问冲突错误

时间:2014-08-29 19:25:55

标签: c++ mfc gdi+ privatefontcollection

按照本演练,演示如何使用字体而不必在C ++中安装它:http://www.codeproject.com/Articles/42041/How-to-Use-a-Font-Without-Installing-it我在ntdll.dll中收到了地址违规错误(0xc0000005)

DialogEx :: OnInitDialog()继承函数中的调用代码如下:

Gdiplus::PrivateFontCollection m_fontcollection;
HINSTANCE instance = AfxGetResourceHandle();
HRSRC res = FindResource(instance, MAKEINTRESOURCE(IDR_MAIN_FONT), L"BINARY");

HGLOBAL mem = LoadResource(instance, res);
void *data = LockResource(mem);
size_t len = SizeofResource(instance, res);

Gdiplus::Status Result = m_fontcollection.AddMemoryFont(data, len); // Exception arises

我调试了电话,一切看起来都不错。长度匹配,没有NullPointers ......

异常发生在gdiplusfontcollection.h

中被调用方法的某处
inline Status
PrivateFontCollection::AddMemoryFont(IN const void* memory,
                                     IN INT length)
{
    return SetStatus(DllExports::GdipPrivateAddMemoryFont(
        nativeFontCollection,
        memory,
        length));
}

无法进一步调试......

如何找出函数调用中出错的方法?

1 个答案:

答案 0 :(得分:-1)

似乎nativeFontCollection为空。 GdiplusStartup method must be called before。不要忘记之后再致电GdiplusShutdown