VC + + method to create MSI file _c language

Source: Internet
Author: User

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) &AMP;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) &AMP;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) &AMP;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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.