2

Following this walkthrough, showing how to use a font without having to install it in C++: http://www.codeproject.com/Articles/42041/How-to-Use-a-Font-Without-Installing-it I get an Adress Violation Error (0xc0000005) in ntdll.dll

The calling code in the DialogEx::OnInitDialog() inherited function is the following:

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

I debugged the calls and everything looks good to me. The length matches and there are no NullPointers...

The Exception happens somewhere in the called method in gdiplusfontcollection.h

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

which was not further debuggable...

Any ideas how to find out what is going wrong in the function call?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vinz
  • 3,030
  • 4
  • 31
  • 52
  • As far as I can tell, Microsoft's documentation has this function as "Not implemented". https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-font-flat Do you have different information? Looks like you have to use the C++ API – Ben Sep 30 '19 at 09:11
  • Do you have to use GDI+? Or can you just use the 'ordinary' GDI interface and load/use your font (from a resource) in 'normal' calls like `CDC::TextOut(…)` and others? If the latter, I can give you some example code to load and use a font from a resource file. – Adrian Mole Sep 30 '19 at 09:58

1 Answers1

0

Seems to be the nativeFontCollection is null. GdiplusStartup method must be called before. Don't forget to call GdiplusShutdown after.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103