VC ++ creates an msi file

Source: Internet
Author: User

Compile your own software installation program

This is just a file for creating the installer type. Of course, it cannot be created. After searching for documents for many days and reading English for many days, we can finally create an msi file. Opening it with orca is the correct file format and it is worth record, the various table relationships in the msi database are complex and can be clearly studied at no later than half past one. record a beginning first. Hope that the experts who have studied msi c ++ programming can give some guidance. The goal is to write a program attached to the software program, so that the installation program msi file can be directly generated after compilation. Just like software that is normally downloaded, you can write a registry, create a desktop shortcut, and register the components and functions used by various software. The simple hello world Program is also very small, and it looks professional.

Sample program
#pragma once//CRT headers.#include 
 
  //windows platform headers.#include 
  
   //msi headers.#pragma comment(lib,"msi.lib")#include 
   
    #include 
    
     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;}
    
   
  
 
The results show that my research is not very clear, but the ultimate goal is to write your own software requires an installation program, so it looks professional, always green software is unwilling.
Zookeeper

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.