【发布时间】:2023-03-21 01:25:02
【问题描述】:
从较旧的 16 位 MSBasic 程序调用用 VS2013 vb.net 编写的程序时出现错误,但如果我从基于 WPF 的库更改为基于 GDI+ 的库,它可以工作。
先介绍一下背景:
http://www.pdfsharp.net 的 PDFSharp 库可以使用 GDI 或 WPF
来自 PDF 夏普网站
PDFsharp 是一个用于处理 PDF 文件的 .NET 库。您创建 PDF 使用 GDI+ 中已知的绘图例程的页面。几乎任何可以 使用 GDI+ 完成也适用于 PDFsharp。只有基本的文本布局 受 PDFsharp 支持,不创建分页符 自动地。相同的绘图例程可用于屏幕、PDF、 或元文件。
PDFSharp 提供的库使用来自 GDI+ 或 WPF 的绘图例程。
问题:
我正在创建的程序是用 VS2013 VB.NET 编写的。我从一个旧的 Microsoft Basic 程序调用这个程序(.EXE 文件),该程序使用command.com 来启动程序。使用command /c pdftest.exe 启动程序时出现错误。但是,使用命令cmd /c pdftest.exe 使用cmd.exe 时,我没有收到错误消息。此外,在使用相同程序但使用 PDFSharp.dll 的 GDI+ 库版本时,我也没有收到错误。
我知道command.com 是 16 位程序,cmd.exe 是 32 位程序。我的理解是command.com使用cmd.exe调用任何程序,那么有什么不同呢? PDFSharp.dll 的 GDI+ 版本也很好。我的测试代码只是一个带有一个按钮的表单,它调用以下代码:
' Create a new PDF document
Dim document As PdfDocument = New PdfDocument
document.Info.Title = "Created with PDFsharp"
' Create an empty page
Dim page As PdfPage = document.AddPage
' Get an XGraphics object for drawing
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
' Draw crossing lines
Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))
' Create a font
Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)
' Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black, _
New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center)
' Save the document...
Dim filename As String = "HelloWorld.pdf"
document.Save(filename)
这是错误
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.TypeInitializationException: The type initializer for 'System.Windows.Media.FontFamily' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MS.Internal.FontCache.Util' threw an exception. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at MS.Internal.FontCache.Util..cctor()
--- End of inner exception stack trace ---
at System.Windows.Media.FontFamily..cctor()
--- End of inner exception stack trace ---
at System.Windows.Media.Typeface..ctor(FontFamily fontFamily, FontStyle style, FontWeight weight, FontStretch stretch)
at PdfSharp.Drawing.FontHelper.CreateTypeface(FontFamily family, XFontStyle style)
at PdfSharp.Drawing.XFont.Initialize()
at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyle style)
at PDFSharpTestWin.PDFSharpTestWin.cmdBasicTest_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我也在尝试在 PDFSharp 论坛上发帖。但是他们的注册系统有问题。我从来没有收到他们的验证电子邮件。所以虽然我也会在这里尝试。
【问题讨论】:
标签: wpf vb.net windows gdi+ 16-bit