c++ - 调用 Gdiplus::PrivateFontCollection.AddMemoryFont 时出现访问冲突错误

标签 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

我调试了调用,一切看起来都很好。长度匹配并且没有空指针...

异常发生在 gdiplusfontcollection.h 中被调用方法的某处

inline Status
PrivateFontCollection::AddMemoryFont(IN const void* memory,
                                     IN INT length)
{
    return SetStatus(DllExports::GdipPrivateAddMemoryFont(
        nativeFontCollection,
        memory,
        length));
}

无法进一步调试...

关于如何找出函数调用中出现的问题有什么想法吗?

最佳答案

似乎是 nativeFontCollection 为空。 GdiplusStartup method must be called before .不要忘记在之后调用 GdiplusShutdown

关于c++ - 调用 Gdiplus::PrivateFontCollection.AddMemoryFont 时出现访问冲突错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25574950/

相关文章:

windows - 如何使用 EnableWindow() 禁用窗口并将其灰显?

c++ - 如何在 MFC 中向 CMenu 添加子菜单?

c# - 当我在 TextChanged 事件中运行相同的代码而不是在 Button Click 中运行相同的代码时,为什么会得到不同的结果?

c++ - 为什么在删除一个函数时,在函数参数中使用指定初始值设定项的这段代码从不明确变为不编译?

c# - 将包含数组字段的结构数组从 C++ 编码到 C#

c++ - 当控件即将失去焦点时,C++ 程序是否会触发一个事件?

c# - 难看的文字问题

c++ - GDI+ - 无法对 Gdiplus::Graphics 执行任何操作 (C++)

c++ - 多站点执行 : Getting rid of virtual table with inheritance (legacy code)

c++ - 具有指定最小长度的线性时间最大连续子序列求和算法