1
当我尝试在VS2012中运行以下代码段时,它会按预期安装字体。然而,当我开始应用从Windows资源管理器,它返回以下错误:“无法安装所需的字体:系统找不到指定的文件”无法安装字体
class Program
{
[DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);
static void Main(string[] args)
{
string spath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\lucon.ttf";
int result = AddFontResource(spath);
int error = Marshal.GetLastWin32Error();
if (error != 0)
{
Console.WriteLine("Unable to install needed font: "+ new Win32Exception(error).Message);
Console.ReadKey();
}
else
{
Console.WriteLine((result == 0) ? "Font is already installed." : "Font installed successfully.");
}
}
}
的lucon.ttf是在正确的文件夹。有人可以解释这一点,并帮助我从Windows资源管理器启动控制台应用程序时运行它吗?
三江源,是工作 – edepperson