Embedded Font Causes a Crash

蓝咒 提交于 2019-11-28 02:22:44
        Marshal.FreeCoTaskMem(FontPtr)

The MSDN documentation for PrivateFontCollection is too obtuse about this. But you need to keep the memory for the added font valid until you can no longer use the font. Or to put it another way, AddMemoryFont() does not make a copy of the font. So your program will fall over with a mysterious GDI+ error when it tries to access the font data and it got overwritten by another unmanaged memory allocation.

Move the FreeCoTaskMem() call to a FormClosed event handler. Or don't bother if closing the form also terminates your program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!