天天看點

打包Windows CE應用程式(一)

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

标題:打包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字段組成。如:

打包Windows CE應用程式(一)

[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可視化工具,使用中文都會存在一定的問題。

繼續閱讀