zoukankan      html  css  js  c++  java
  • C#注册OCX控件

    注意

    COM组件注册到注册表中的位置,是CLSID还是TypeLib

    注册方法

    代码执行

    //声明注册方法
    [DllImport("C:\Windows\barcodex.ocx")]
    public static extern int DllRegisterServer();//注册时用
    //DLL注册
    int i = DllRegisterServer();
    if (i >= 0)
    {
      return true;
    }
    else
    {
      return false;
    }

    调用控制台执行

    string file="";//ocx的文件名称
    string fileFullName = """ + file + """;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start("regsvr32", fileFullName + " /s");
     

    反注册(卸载)方法

    代码执行

    //声明注册方法
    [DllImport("C:\Windows\barcodex.ocx")]
    public static extern int DllUnregisterServer();//取消注册时用
    //DLL反注册
    int i = DllUnregisterServer();
    if (i >= 0)
    {
      return true;
    }
    else
    {
      return false;
    }

    调用控制台执行

    string file="";//ocx的文件名称
    string fileFullName = """ + file + """;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start("regsvr32", fileFullName + " /s /u");
     

    检测是否安装的方法

    注册在CLSID目录下

    String clsid="";//ocx组件的ClassID,不会重复
    //设置返回值
    Boolean result = false;
    String key = String.Format(@"CLSID{0}", clsid);//注意{},设置的clsid变量的id必须带{}
    RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(key);
    if (regKey != null)
    {
      result = true;
    }
    return result;
    返回的regKey对象不为null,则已经表示安装。

    注册在TypeLib目录下

    String clsid="";//ocx组件的ClassID,不会重复
    //设置返回值
    Boolean result = false;
    //检查方法,查找注册表是否存在指定的clsid
    String key = String.Format(@"TypeLib{0}", clsid);//注意{},设置的clsid变量的id必须带{}
    RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(key);
    if (regKey != null)
    {
      result = true;
    }
    return result;
     
  • 相关阅读:
    一sqlite分页 语句,
    array调用排序,返回的数组要 重新赋值,
    sublime text3快速编辑选中多行
    sublime text3实现多行快速编辑Ctrl+E或者Tab
    sublime使用Markdown Preview标记语言
    解决sublime package control 出现There are no packages available for installation
    sublime text 3安装html-css-js prettify后使用时报错An unhandled OS error was encountered
    sublime格式化插件---HTML-CSS-JS Prettify美化代码
    node=day5
    封装异步API
  • 原文地址:https://www.cnblogs.com/masonblog/p/8628672.html
Copyright © 2011-2022 走看看