我有一个向PDF文件添加文本的应用程序,我有一个axAcroPDF1预览面板,借用acrobat来显示PDF文件的状态,但对于程序的功能来说不是必需的,所以我希望即使没有安装Acrobat,程序仍然启动,尽管功能更有限, 然后用户不会有一个预览面板,这很好。 我该怎么做?
我唯一能想到的尝试是在程序启动时初始化 this.axAcroPDF1 时添加一个捕获/异常,这允许我弹出一条消息,指出需要 Adobe 阅读器,但程序在那之后仍然崩溃,所以我希望无论如何都要启动程序,并且在未安装 Adobe 时不要调用它, 或你们有的任何其他建议,以便此应用程序仍然可以在有或没有 Adobe 的情况下运行。
我知道如何检查是否安装了 Adobe,但我不知道如何将结果应用于我的程序。
初始化时的 catch 异常给出了以下错误(我是一个菜鸟,所以可能没有在这里提供好的信息):
System.Runtime.InteropServices.COMException (0x80040154): Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.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)
解决方案:我决定使用 Inno Installer,因为我有一些 DLL 文件,并且在安装程序脚本中,我做了一个 adobe 检查,如果他们没有 Adobe 或正确的版本,我会提示用户下载阅读器。 以下是检查 Adobe 的基本代码:
[Code]
procedure ExitProcess(exitCode:integer);
external 'ExitProcess@kernel32.dll stdcall';
function GetAcrobatReaderVersion(): String;
var
sVersion: String;
begin
sVersion := '';
RegQueryStringValue( HKLM, 'SOFTWAREMicrosoftWindowsCurrentVersionApp PathsAcroRd32.exe',
'', sVersion );
GetVersionNumbersString( sVersion , sVersion );
Result := sVersion;
end;
function GetAcrobatVersion(): String;
var
sVersion2: String;
begin
sVersion2 := '';
RegQueryStringValue( HKLM, 'SOFTWAREMicrosoftWindowsCurrentVersionApp PathsAcrobat.exe',
'', sVersion2 );
GetVersionNumbersString( sVersion2 , sVersion2 );
Result := sVersion2;
end;
function NextButtonClick(CurPage: Integer): Boolean;
begin
// by default go to next page
Result := true;
if CurPage = wpWelcome then
begin
if Length( GetAcrobatReaderVersion + GetAcrobatVersion() ) = 0 then
begin
MsgBox( 'adobe not detected', mbInformation, MB_OK );
Result := false;
ExitProcess(0);//adobe isn't installed, so exit installer
end
else
//MsgBox( 'Acrobat reader installed is version ' + GetAcrobatReaderVersion() ,
MsgBox( 'adobe detected', mbInformation, MB_OK );
end;
end;