使用VC++可以編寫自己的軟件安裝程序,其實這只是為了創建安裝程序類型的msi文件,MSI數據庫中的各種表都很復雜,無法清楚地研究出來。本文是武林技術頻道小編介紹的VC++創建msi文件的方法,一起來看看吧!
具體示例程序如下:
#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>
上述是武林技術頻道小編為大家介紹的VC++創建msi文件的方法,其實這個程序都可以實現簡單的基本功能,我們可以根據自己的需要進一步開發其他個性化功能,以滿足自己的需求。
|
新聞熱點
疑難解答
圖片精選