在Installscript中使用的.NET dll中使用布尔返回值
本文关键字:布尔 返回值 dll NET Installscript | 更新日期: 2023-09-27 18:25:59
我已经创建了一个要在Installscript中使用的.NET dll。它基本上安装证书、删除证书并检查证书是否已经存在。这是我的Exists方法:
[ComVisible(true)]
public bool Exists(string thumbPrint)
{
try
{
...
//Check if the certificate exists on the store.
var certCollection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbPrint, false);
return (certCollection.Count > 0);
}
catch (Exception exception)
{
...
}
}
这是安装脚本代码
szDLLPath = SUPPORTDIR ^ "X509Framework.dll";
szClassName = "X509Framework.X509StoreProcessor";
DotNetUnloadAppDomain("X509FrameworkDomain");
try
set oX509Store = DotNetCoCreateObject(szDLLPath, szClassName, "X509FrameworkDomain");
catch
SprintfBox (INFORMATION, "Error","Error occured: %i'n'n%s'n'n%s", Err.Number, Err.Description, Err.LastDllError);
abort;
endcatch;
try
nReturn = oX509Store.Exists(FinArchCodeSigningSha);
catch
SprintfBox (INFORMATION, "Error","Error occured: %i'n'n%s'n'n%s", Err.Number, Err.Description, Err.LastDllError);
abort;
endcatch;
在本例中,无论证书是否存在,当我在Installscript中调试nReturn
时,它始终是-1
。(当然,从.NET程序来看,它运行得很好)然后我尝试使用int
作为返回值,这就成功了。所以有一个变通办法。
但我想知道是否有人知道为什么我不能使用bool
作为Installscript中使用的.NET dll的返回值。
最终它变得非常简单。Installshield无法解释.NET中的布尔字段。必须使用int。
.NET程序必须返回一个int
值:1
用于TRUE
,0
用于FALSE
(我知道很标准)
然后我在Installshield中将返回值设置为BOOL
变量。