设为首页 加入收藏

TOP

VC++ 创建msi文件
2015-07-24 05:52:04 来源: 作者: 【 】 浏览:4
Tags:创建 msi 文件

编写自己软件的安装程序

这里只是创建安装程序类型的文件,当然创建出来也是不能用的。找了好多天资料,看了好多天英语,终于能创建出msi文件了,用orca打开是正确的文件格式,值得自己记录一下了,msi数据库里面的各种表关系复杂,不是一时半刻能研究清楚的,现在先记录一个开头吧。希望研究过msi c++ 编程的大神们给点指导。想实现的目标是写一个程序附到软件程序后面,这样可以在编译完成后直接会有安装程序msi文件。就像平常下载的软件,可以写注册表,创建桌面快捷方式,注册各种软件用到的组件和功能。就简单的hello world 程序也是麻雀虽小,五脏俱全就显得专业了。

示例程序

#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; }  
     
    
   
  

结果展示

\

总结

现在我研究的还不是很明白,不过最终的目的就是自己编写的软件需要一个安装程序,这样子就看着专业一些了,总是绿色软件很是不甘心。
??
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇CodeForces 7D Palindrome Degree.. 下一篇Codeforces 14D Two Paths 树的直..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: