CAB 制作

 

如果你写的是ActiveX元件,而且希望将一堆相关的dll复制到使用者电脑的c:/windows/system32/自订的目录,你就要会写INF.

INF档全名是information file ,里面放着如何安装你的软体在使用者电脑的指令.基本上, IE 3.0以后的浏览器都是用 Internet Component Download 这个service自动安装你的ActiveX软体,而这个service吃的就是INF档.

详细说明: http://msdn.microsoft.com/en-us/library/aa741213(VS.85).aspx

本文大纲

  1. 最简单INF 档写作范例
  2. 最简单建立CAB 档范例

 

开始

C & C++ 的程式设计师都知道每一个程式都有一个进入点, 也就是第一个执行的函式. 那么INF 档的main 是哪一个呢?

是这样的.

如果你的INF档没有 [Add.Code] and [Setup Hooks] 那就会找[DefaultInstall] section开始执行

我们今天用 [DefaultInstall] 的方法,主要原因是standard Microsoft Win32 INF file提供更有弹性的功能.所以下面的inf档里面没有[Add.Code]与[Setup Hooks] sections.


现在开始动手吧. 
我希望当使用者安装我的ActiveX 元件时, 做下面工作...

1.把a.dll, b.dll, c.ocx复制到c:/windows/system32/jing 目录中 
2.把JingPlugin1.dll与JingPlugin2.dll复制到c:/windows/system32/jing/plugins 
3. 若使用者没有这两个目录,系统必须要自己建立 
4. b.dll 与c.ocx 必须注册, 而且b.dll 必须先注册然后才是c.ocx

 

最简单INF 档写作范例

; ---------------------------- d.inf ------------------ ------ 
; 这个inf 档必须要放在cab 档里面一起散布出去

[version] 
signature=$Chicago$ 
AdvancedINF=1.0

; Step 1: (这是注解) INF file 的第一个执行指令 
; CopyFiles = 要复制的档案列表sections 
; RegisterOCXs = 要注册的档案列表(你的元件可能有一堆dll 或ocx 要注册)
 
[DefaultInstall]
CopyFiles= MyFiles, MyInf, PluginFileList 
RegisterOCXs=RegisterOCXSection

; Step 2: 指定这些档案要复制的目的地 
; INF中的号码意义: see http://www.osronline.com/ddkx/install/create-inf_3aav.htm

[DestinationDirs] 
;在 MyFiles的档案,全部装到c:/Windows/system32/jing 
; 目录里面(11 对应到system32)

MyFiles=11,jing ;你看的没错,就是11,jing

; 在MyInf 描述的档案, 全部装到c:/Windows/Inf 里面
MyInf=17 

; 把PluginFileList 描述的档案, 全部倒进 
; c:/Windows/system32/jing/plugins 里面
 
PluginFileList=11,jing/plugins ; 同样的11,jing/plugins

 

; 如果要把一堆档案放到任意位置, 则使用-1即可

; 例如: 下面的指令会把PluginFileList 的一堆档案放到c:/jing/plugins 里面

; PluginFileList=-1,c:/jing/plugins 

; Step 3: 定义MyFiles 中包含哪些档案 
[MyFiles]

a.dll=a.dll ; a.dll档案的详细资料,参考a.dll描述 
b.dll=b.dll ; b.dll档案的详细资料,参考b.dll描述 
c.ocx=c.ocx ; c.ocx档案的详细资料,参考c.ocx描述

[a.dll] ; a.dll描述 
file=thiscab ;这个档案从目前的cab档解析出来 
FileVersion=0,0,0,0 
;DestDir=11 ;这个档案要复制到C:/Windows/system32但适用于[Add.Code ]的方式,目前使用standard Microsoft Win32 INF file的方式进行描述,所以DestDir指令无效.

[b.dll] ; b.dll描述 
file=thiscab ;这个档案从目前的cab档解析出来 
FileVersion=0,0,0,0 
RegisterServer=yes 

[c.ocx] ; c.ocx描述 
file=thiscab ;这个档案从目前的cab档解析出来 
FileVersion=0,0,0,0 
RegisterServer=yes 

; Step 4: 定义MyInf 中包含哪些档案 
[MyInf] 
d.inf=d.inf ; d.inf档案的详细资料,参考d.inf描述 

[d.inf] ;d.inf档案的详细描述 
file-win32-x86=thiscab
FileVersion=1,0,0,0 

; Step 5: 定义PluginFileList 中包含哪些档案 
[PluginFileList] 
JingPlugin1.dll=JingPlugin1.dll ;详细资料,参考JingPlugin1.dll描述 
JingPlugin2.dll=JingPlugin2.dll ;详细资料,参考JingPlugin2.dll描述 
[JingPlugin1.dll] 
file=thiscab ;这个档案从目前的cab档解析出来 
FileVersion=0,0,0,0 
[JingPlugin2.dll] 
file=thiscab ;这个档案从目前的cab档解析出来 
FileVersion=0,0,0,0


; Step 6: 要注册的全部放在这里 
[RegisterOCXSection] 
"%11%/jing/b.dll" ;自动注册放在system32/jing里面的b.dll 
"%11%/jing/c.ocx" ;自动注册放在system32/jing里面的c.ocx

; ---------------------------- end of d.inf ---------------- --------

 

最简单建立CAB档范例制作cab档,把你的ActiveX元件散布出去

Step 1: 假设你的元件档案结构如下:

a.dll 
b.dll 
c.ocx 
d.inf 
plugins 
|______ JingPlugin1.dll 
|______ JingPlugin2.dll

 

Step 2: 下达压缩指令 
"C:/Program Files/Microsoft Visual Studio 8/Common7/Tools/Bin/cabarc.exe" -r -s 6144 n my.cab c.ocx d.inf a.dll b.dll plugins/*.dll 
Note:

1. 你不能用-p 的方式建立cab, 否则当安装时, 会找不到子目录里面的档案 
2. 6144 是留给将来数位签章使用的空间 

Step 3: 完成产生my.cab

 

Enjoy. 希望对你有帮助.

by Jing

 

延伸阅读

[1] Using INF Files 
[2] 一堆INF档可用的指令

 

[3] Jing, "如何产生certification 文件, 用来sign 你的软体?," 2009/5
http://mqjing.blogspot.com/2009/05/certification-sign.html

[4] Jing, "如何为你的ActiveX 元件(cab 档) 加入数位签章-- signtool?," 2009/3
http://mqjing.blogspot.com/2009/03/plugin-activex-cab-signtool.html

[5] Jing, "ActiveX 元件版本问题," 2009/3
http://mqjing.blogspot.com/2009/03/plugin-activex.html

[6] Jing, "INF 档里面可不可以使用变数?," 2009/3
http://mqjing.blogspot.com/2009/03/plugin-inf.html

 

 

 

相关连接:

http://www.jzxue.com/Html/asp/111301042371118.html

http://kiki1120.javaeye.com/blog/512474

http://hi.baidu.com/david5/blog/item/560eca11fc580812b8127be1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值