打包Windows CE应用程序(一)

来源:互联网 发布:mysql 设置编码 utf8 编辑:程序博客网 时间:2024/05/19 16:21

=============================================================

标题:打包Windows CE应用程序(一)

日期:2011.4.29

姓名:朱铭雷

=============================================================

VS IDE中,可以直接建立一个“智能设备CAB项目”,然后就是修改一下属性,添加依赖文件,添加快捷方式和注册表,总之比较简单。现在来使用一种最原始的方法,自己编写inf文件,然后命令行调用cabwiz.exe进行打包。其实在实际工作中,不必要这么做,完全是给自己找麻烦。但这次俺要看看MSDN文档,研究些细枝末节,知其然而知其所以然。

inf文件的格式是什么样的?包含什么?如何写?msdn中有一个CAB Wizard进行了全面细致的讲解。首先看inf文件包含写什么:

Section

Required

Description

Version

Yes

Describes the creator and version of the application.

Platform

No

Describes the platform version that the application is targeted for.

CEStrings

Yes

Contains string substitutions for application and directory names.

Strings

No

Contains string definitions for one or more strings.

CEDevice

No

Describes the hardware platform that the application is targeted for.

DefaultInstall

Yes

Describes the default method used to install the application.

CopyFiles

Yes

Specifies the list of files that the .cab file copies to the target device.Appears in the DefaultInstall section.

AddReg

No

Specifies the keys and values that the .cab file adds to the registry on the target device.Appears in the DefaultInstall section.

CEShortcuts

No

Specifies the shortcuts that are created on the target device.Appears in the DefaultInstall section.

SourceDisksNames

Yes

Contains the name and path of the directories on the hard disk where the application files reside.

SourceDisksFiles

Yes

Contains the source filenames of the files that comprise the application.

DestinationDirs

Yes

Contains the names and paths of the destination directories for the application on the target device.

Yes代表inf文件中必须要包含的部分,No则是可选的。在MSDN中,对于inf文件中的每个Section都给出了详细的格式介绍和示例。根据其介绍和示例,很快写出了自己的inf

; ver1.0 by zhuyf - test -

[Version]

Signature = "$Windows NT$"

Provider = "SureKam"

CESignature = "$Windows CE$"

 

[CEStrings]

AppName="GZPD"

InstallDir=%CE1%/%AppName%

 

[DefaultInstall]

CopyFiles = CopyToProgramFiles

AddReg = RegData

CEShortcuts = Shortcuts

 

[CopyToProgramFiles]

"GZPD.exe",GZPD.exe

"SQLite3.dll",SQLite3.dll

"db_Gdzc.db",db_Gdzc.db

"db_User.db",db_User.db

 

[RegData]

HKCU,Software/%AppName%,MajorVer,0x00010001,1

HKCU,Software/%AppName%,MinorVer,0x00010001,0

 

[DestinationDirs]

CopyToProgramFiles = 0,%InstallDir%

Shortcuts = 0,%CE2%/Desktop

 

[Shortcuts]

%AppName%,0,GZPD.exe,%CE4%

%AppName%,0,GZPD.exe,%CE11%

 

[SourceDisksNames]

1 = ,"Common files",,C:/

 

[SourceDisksFiles]

GZPD.exe = 1

SQLite3.dll = 1

db_Gdzc.db = 1

db_User.db = 1

一段一段简单看看。

; ver1.0 by zhuyf - test –”是注释,以“;”开头。

[Version]

Signature = "$Windows NT$"

Provider = "SureKam"

CESignature = "$Windows CE$"

指定一些相关信息,基本上只要Provider改成自己公司的名字即可。这个是有用的,在控制面板的删除程序中,显示的程序名,就要由Provider字段组成。如:

[CEStrings]

AppName="GZPD"

InstallDir=%CE1%/%AppName%

包含应用程序名字,默认安装目录等信息。这里看到一个“%CE1%”,它是一个Windows CE String。代表的含义请看下表:

Windows CE String

Directory

%CE1%

Program Files

%CE2%

Windows

%CE4%

Windows/StartUp

%CE5%

My Documents

%CE8%

Program Files/Games

%CE11%

Windows/Start Menu/Programs

%CE14%

Windows/Start Menu/Programs/Games

%CE15%

Windows/Fonts

%CE17%

Windows/Start Menu

[DefaultInstall]

CopyFiles = CopyToProgramFiles

AddReg = RegData

CEShortcuts = Shortcuts

描述应用程序默认安装哪些东西。这里是包含一些文件,注册表,还有快捷方式。

[CopyToProgramFiles]

"GZPD.exe",GZPD.exe

"SQLite3.dll",SQLite3.dll

"db_Gdzc.db",db_Gdzc.db

"db_User.db",db_User.db

默认需要打包进来的全部文件。

[RegData]

HKCU,Software/%AppName%,MajorVer,0x00010001,1

HKCU,Software/%AppName%,MinorVer,0x00010001,0

需要添加进Windows CE注册表中的一些信息,这里添加了该应用程序的软件主,次版本号。

[DestinationDirs]

CopyToProgramFiles = 0,%InstallDir%

Shortcuts = 0,%CE2%/Desktop

描述安装路径的一些信息,这里是上面打包的4个文件的安装路径,和快捷方式的一个默认安装路径。

[Shortcuts]

%AppName%,0,GZPD.exe,%CE4%

%AppName%,0,GZPD.exe,%CE11%

要创建并安装到目标系统的快捷方式,这里一共放了2个快捷方式。

[SourceDisksNames]

1 = ,"Common files",,C:/

打包文件所在的磁盘路径,这里是在C盘的根目录下。

[SourceDisksFiles]

GZPD.exe = 1

SQLite3.dll = 1

db_Gdzc.db = 1

db_User.db = 1

要打包的文件列表及目录信息。

最后强调一下,在inf文件中,最好不要出现xml或者Windows CE文件系统保留字。

上面只是对一个inf文件的简单介绍,结合这个示例在加上MSDN中的“Information File”介绍很容易就能看懂并编写出一个符合自己需求的inf文件。

inf文件编写完毕之后,在命令行中调用cabwiz.exe进行打包操作。这也有一个语法:

"inf_file" [dest_dir] [err_file]

[cpu_type [hardware_platform_label]] [platform_label [platform_label]]

示例:

cabwiz.exe  "c:/myfile.inf"  /err myfile.err

还有一个问题,就是无论自己编写inf文件,还是使用VS可视化工具,使用中文都会存在一定的问题。

原创粉丝点击