采用VC++可以编写自己软件的安装程序。这里只是创建安装程序类型的msi文件,用orca打开是正确的文件格式,值得自己记录一下了,msi数据库里面的各种表关系复杂,不是一时半刻能研究清楚的。本文仅作一浅析,实现写一个程序附到软件程序的后面,这样可以在编译完成后直接会有安装程序msi文件。就像平常下载的软件,可以写注册表,创建桌面快捷方式,注册各种软件用到的组件和功能。
具体示例程序如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#pragma once
//CRT headers.
#include <TCHAR.H>
//windows platform headers.
#include <WINDOWS.H>
//msi headers.
#pragma comment(lib,"msi.lib")
#include <MSI.H>
#include <MSIQUERY.H>
INT APIENTRY _tWinMain(
HINSTANCE ,
HINSTANCE ,
LPTSTR ,
INT )
{
MSIHANDLE msiHandle=NULL;
//create msi database.
UINT openResult=MsiOpenDatabase(
_T( "Setup.msi" ),
MSIDBOPEN_CREATEDIRECT,
&msiHandle);
//create msil database failed.
if (openResult != ERROR_SUCCESS)
{
LPVOID formatMsg=NULL;
MSIHANDLE errorCode=MsiGetLastErrorRecord();
//format error code to string.
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),
( LPTSTR )&formatMsg,
0,
NULL);
//output error message.
MessageBoxEx(
NULL,
( LPTSTR )formatMsg,
_T( "tip window" ),
MB_OK,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT));
//free message buffer.
LocalFree(formatMsg);
formatMsg=NULL;
return -1;
}
//commit msi database.
UINT commitResult=MsiDatabaseCommit(msiHandle);
if (commitResult != ERROR_SUCCESS)
{
LPVOID formatMsg=NULL;
MSIHANDLE errorCode=MsiGetLastErrorRecord();
//format error code to string.
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),
( LPTSTR )&formatMsg,
0,
NULL);
//output error message.
MessageBoxEx(
NULL,
( LPTSTR )formatMsg,
_T( "tip window" ),
MB_OK,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT));
//free message buffer.
LocalFree(formatMsg);
formatMsg=NULL;
return -1;
}
//close msi database handle.
UINT closeResult=MsiCloseHandle(msiHandle);
if (closeResult != ERROR_SUCCESS)
{
LPVOID formatMsg=NULL;
MSIHANDLE errorCode=MsiGetLastErrorRecord();
//format error code to string.
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
errorCode,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),
( LPTSTR )&formatMsg,
0,
NULL);
//output error message.
MessageBoxEx(
NULL,
( LPTSTR )formatMsg,
_T( "tip window" ),
MB_OK,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT));
//free message buffer.
LocalFree(formatMsg);
formatMsg=NULL;
return -1;
}
return 0;
}
</SPAN>
|
本程序仅实现简单的基本功能,读者可根据自身的需要进一步开发其他个性化功能,以满足自身需求。
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 101
-
Linux 下安装 memcached 及 memcacheq的方法
2025-05-27 74 -
2025-05-29 70
-
2025-05-25 91
-
2025-05-25 102
热门评论