AddFontResource - help

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

Hi,

I'm a total C++ neophyte, and we've got a short deadline to turn around.
Essentially, I need a utility that installs a series of fonts on a given
system, and I don't know whether the .NET runtime is installed on that
system, so I want something that will run w/o the .NET runtime, VB dlls,
etc. I know that I need to use AddFontResource, then WriteProfileString,
followed by doing a SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0&). I'm
using VC++ in Visual Studio .NET 2.0. However, I'm having a very hard time
with LPCTSTR and making this whole thing work.

Here is my code:
LPSTR fontPath = "C:\\ZQMRS___.pfm|C:\\ZQMRS___.PFB";
int fontCount = AddFontResource((LPCTSTR)fontPath);
WriteProfileString((LPCWSTR)"Fonts", (LPCWSTR)"Adobe Myriad Pro",
(LPCWSTR)fontPath);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);


This is probably totally wrong, but it's the best I've come up with so far.
Anyway, fontCount always is returned as 0 (zero) from the AddFontResource
call, so it's failing, but there is no error message available. Note that
these are PFM files, so we do have to include all associated files using the
| character.

Does anybody have any ideas or samples of how this can be done?

Thanks very much in advance!

Jim
 
We found a much easier way: use a self-extracting zip file, then run a batch
file at the end that copies the fonts to the font folder and then opens an
Explorer window to the Fonts folder.

This didn't seem like a big deal for somebody who is pretty C++ savvy, yet
there were no responses on this. Was I wrong?

Jim
 
Back
Top