在Installscript中使用的.NET dll中使用布尔返回值

时间:2013-08-02 08:34:05

标签: c# installscript

我创建了一个要在Installscript中使用的.NET dll。它基本上安装证书,删除证书并检查证书是否已存在。 这是我的存在方法:

[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的返回值。

1 个答案:

答案 0 :(得分:3)

最后结果很简单。 Installshield无法解释.NET中的布尔字段。不得不使用int。

.NET程序必须返回int值: 1TRUE0FALSE(我非常标准)

然后我将返回值设置为Installshield中的BOOL变量。