zoukankan      html  css  js  c++  java
  • 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;     
     


     

                   

  • 相关阅读:
    C++解析(5):内联函数分析
    C++解析(4):引用的本质
    C++解析(3):布尔类型与三目运算符
    C++解析(2):进化后的 const 分析
    C++解析(1):C到C++的升级
    net与树莓派的情缘(二)
    net与树莓派的情缘(一)
    Ngin 简单配置文件
    sql geography类型(地理坐标) 赋值
    MongoDB与c#(二)简单例子 使用1.7版本驱动
  • 原文地址:https://www.cnblogs.com/forneter/p/3815447.html
Copyright © 2011-2022 走看看