I wrote a small exe that can install a font, the path to the font is passed via an argument.
System.ComponentModel.Win32Exception (0x80004005): system cannot find the file specified
Here is the code:
public static class FontInstaller
{
[DllImport(@"C:\Windows\System32\gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]string lpFileName);
static void Main()
{
InstallFont(@"C:\Fonts\font.ttf");
}
private static void InstallFont(string fontPath)
{
// Try install the font.
var result = AddFontResource(fontPath);
var error = Marshal.GetLastWin32Error();
if (error != 0)
{
Console.WriteLine(new Win32Exception(error));
}
else
{
Console.WriteLine(result == 0 ? "Font is already installed." : "Font installed successfully.");
}
}
}
What is going wrong here? Where is the difference between F5 and Ctrl F5 in that specific case?
User contributions licensed under CC BY-SA 3.0