[ create a new paste ] login | about

Link: http://codepad.org/G0lWvlPJ    [ raw code | fork ]

C++, pasted on Dec 11:
// CustomAction.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"


extern "C" UINT __stdcall Install(MSIHANDLE hInstall)
{
	PMSIHANDLE hRecord = MsiCreateRecord(0);
	MsiRecordSetString(hRecord, 0, TEXT("Hello MSI!"));
	MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_USER + MB_OK), hRecord);
	return ERROR_SUCCESS;
}

extern "C" UINT __stdcall Commit(MSIHANDLE hInstall)
{

		TCHAR* szValueBuf = NULL;
		DWORD cchValueBuf = 0;
		UINT uiStat =  MsiGetProperty(hInstall, TEXT("targ"), TEXT(""), &cchValueBuf);
		//cchValueBuf now contains the size of the property's string, without null termination
		if (ERROR_MORE_DATA == uiStat)
		{
			++cchValueBuf; // add 1 for null termination
			szValueBuf = new TCHAR[cchValueBuf];
			if (szValueBuf)
			{
				uiStat = MsiGetProperty(hInstall, TEXT("targ"), szValueBuf, &cchValueBuf);
			}
		}
		if (ERROR_SUCCESS != uiStat)
		{
			if (szValueBuf != NULL) 
				delete[] szValueBuf;
			return ERROR_INSTALL_FAILURE;
		}

		// custom action uses MyProperty
		// ...
		MessageBox(GetForegroundWindow( ), szValueBuf, TEXT("Value Data"), MB_OK | MB_ICONINFORMATION);

		delete[] szValueBuf;

		return ERROR_SUCCESS;
	

	/////targ="[TARGETDIR]\"
	//// max. USERNAME size, from CustomerInformation panel
	//const DWORD MAX_USERNAME_LEN = 500;

	//// initialize empty string and size buffer
	//TCHAR UserName[MAX_USERNAME_LEN + 1] = {0};
	//DWORD Buffer = MAX_USERNAME_LEN + 1;

	//// read and display the initial value of USERNAME
	//MsiGetProperty(hInstall, TEXT("targ"), UserName, &Buffer);

	////sizeof(UserName)

	//MessageBox(
	//	GetForegroundWindow( ),
	//	UserName, TEXT("USERNAME"),
	//	MB_OK | MB_ICONINFORMATION);

	//// change the value of USERNAME
	//MsiSetProperty(hInstall, TEXT("targ"),
	//	TEXT("Valued Customer"));

	//


	//return ERROR_SUCCESS;
}

extern "C" UINT __stdcall Rollback(MSIHANDLE hInstall)
{
	return ERROR_SUCCESS;
}

extern "C" UINT __stdcall Uninstall(MSIHANDLE hInstall)
{
	return ERROR_SUCCESS;
}


Create a new paste based on this one


Comments: