C#注册OCX控件
2024-09-02 00:44:05
注意
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;
最新文章
- visual studio 两个以上sln 引用同一个project ,生成时会改变projectguid问题
- 8.31 js基础总结1
- tomcat开机启动
- 学习WPF——WPF布局——了解布局容器
- SQL compute by 的使用
- 【CodeForces 621B】Wet Shark and Bishops
- poj 3164 最小树形图
- 代码优化—From <;effective C++>;
- Hadoop开发环境搭建
- Spring AOP在pointcut expression解析表达式 并匹配多个条件
- linux ip 转发设置 ip_forward
- 【莫比乌斯反演】BZOJ3309 DZY Loves Math
- Spring Boot笔记七:扩展Spring MVC
- ionic使用iframe时无法显示网页或报错
- laravel的seeder数据填充
- 使用Android绘图技术绘制一个椭圆形,然后通过触摸事件让该椭圆形跟着手指移动
- 802.11ax前瞻4:802.11ax与HiperLan
- .Protobuf,GRpc,Maven项目出现UnsatisfiedDependencyException、ClassNotFoundException、BuilderException等异常
- 关于 Chrome Console 查看DOM详情细节的奇思淫巧
- MySQL:入门
热门文章
- Java基础教程——运算符
- 关于深度学习之中Batch Size的一点理解(待更新)
- 冲刺随笔——Day_Three
- JZOJ8月8日提高组反思
- 修改MongDB的数据类型
- 2019 ACM/ICPC North America Qualifier G.Research Productivity Index(概率期望dp)
- 喝完可乐桶后程序员回归本源,开源Spring基础内容
- 第1.2节 Python学习环境的使用
- PyQt(Python+Qt)学习随笔:Action功能详解及Designer中的操作方法
- PyQt(Python+Qt)学习随笔:toolButton的popupMode属性