[Wix]如何向MSI安装包中调用的dll中传递参数

真郁闷,写好的东西,一个不小心给弄没了先把dll的code贴上来,vs 2003.net下编译通过 描述啥的改天补~~

#include 
#include 
#include 
#include 

#pragma comment(lib, "msi.lib")

#ifndef _UNICODE
#define _UNICODE
#endif

#ifndef UNICODE
#define UNICODE
#endif

#ifndef MAX_LENGTH
#define MAX_LENGTH 1024
#endif

// I don't know how to get HWND from the parameter of MSIHANDLE.
// So I use the FindWindow API to do that.
HWND GetInstallWnd(LPTSTR lpszFullTitle, LPTSTR lpszTitle)
{
	HWND hwnd;

	// "MsiDialogCloseClass" is the Class of setup window _
	// When you run setup package like double click, you may get this class.
	hwnd = FindWindow(_T("MsiDialogCloseClass"), lpszFullTitle);
	if(NULL == hwnd)
		hwnd = FindWindow(_T("MsiDialogCloseClass"), lpszTitle);

	// "#32770" is the Class of setup window _
	// When you run setup package like "Msiexec /x", you may get this class.
	if(NULL == hwnd)
		hwnd = FindWindow(_T("#32770"), lpszFullTitle);

	if(NULL == hwnd)
		hwnd = FindWindow(_T("#32770"), lpszTitle);

	if(NULL == hwnd)
		return NULL;

	return hwnd;
}

extern "C" __declspec(dllexport)
UINT SampleFunction(MSIHANDLE hInstall)
{
	TCHAR strTitle[MAX_LENGTH - 6] = {0};
	DWORD dwStrLen = sizeof(strTitle);

	// MsiGetProperty is the API, which can get the Propety in wxs script.
	// You can find the detail of this API in MSDN.
	MsiGetProperty(hInstall, _T("ProductName"), strTitle, &dwStrLen);

	TCHAR strFullTitle[MAX_LENGTH] = {0};

	_tcscpy(strFullTitle, strTitle);
	_tcscat(strFullTitle, _T(" Setup"));

	HWND hwnd = GetInstallWnd(strFullTitle, strTitle);

	TCHAR strMessage[MAX_LENGTH] = {0};
	_stprintf(strMessage, _T("Welcome to use %s."), strTitle);

	// After get HWND of setup package, the MessageBox can cover the setup window.
	MessageBox(hwnd, strMessage, strFullTitle, MB_OK|MB_TOPMOST);

	return ERROR_SUCCESS;
}

ps: 宝贝回家了,我好想她。~~~

One thought on “[Wix]如何向MSI安装包中调用的dll中传递参数”

发表评论

邮箱地址不会被公开。 必填项已用*标注