InstallShield系列(二) 调用C#生成的dll

(1)使用库生成dll。

注意:(1)InstallShield2010只能调用Framwork 3.5生成的dll

     (2)设置dll为Com可见。在Properties里的AssemblyInfo.cs的ComVisible设为true,默认为false。

(2)调用示例:

  下面的是验证数据库的连接的范例,生成的Dll名为ISHelper:

  C#的代码

  public class SqlServer
    {
        public bool CheckConn(string server, string dbName, string userName, string pwd)
        {

            using (SqlConnection conn = new SqlConnection())
            {
                server = DealWithString(server);
                dbName = DealWithString(dbName);
                userName = DealWithString(userName);
                pwd = DealWithString(pwd);
                conn.ConnectionString = String.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", server, dbName, userName, pwd);
                try
                {
                    conn.Open();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
}

 InstallShield调用的代码:

导入dll:方法

左边的视图中选择Behavior and Logic 中的Support Files/BillBoards.在Support Files菜单中选择 语言(此处为中文简体),在右侧Files试图右键InsertFiles插入ISHelper.dll文件。

IS里的脚本:

主要使用方法CoCreateObjectDotNet

prototype CheckConnection(string,string,string,string); 
 function CheckConnection(server,dbName,userName,pwd) 
  string szDllPath; 
  object oMyTest;   
 begin     
  szDllPath= SUPPORTDIR^"ISHelper.dll"; //dll文件路径
 set oMyTest=CoCreateObjectDotNet(szDllPath,"ISHelper.SqlServer") ;//后面的字符串为命名空间
       if(oMyTest.CheckConn(server,dbName,userName,pwd)) then       
       return TRUE;  
       else         
       return FALSE; 
       endif;        
 end;     
 


 

               

原文地址:https://www.cnblogs.com/forneter/p/3815447.html