The use of VC + + can write their own software installation program. Here just create the installer type of MSI file, with Orca Open is the correct file format, worth recording, MSI database inside the various table relationship is complex, not won't be can study clearly. This article only makes one simple analysis, realizes writes a program to attach to the software program's behind, thus may have the installer MSI file directly after the compilation completes. Just like the usual downloaded software, you can write the registry, create desktop shortcuts, and register the components and functions used by various software.
The specific example program is as follows:
#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>
This program only realizes simple basic function, the reader may further develop other personalization function according to own need, in order to satisfy own demand.