views:

296

answers:

1

I've got a DLL from an old WiSE installer that i'm trying to get working in WiX, so i'm pretty sure the DLL works with MSI-based installers.

Here is my definition:

<Binary Id="SetupDLL" SourceFile="../Tools/Setup.dll" />
<CustomAction Id="ReadConfigFiles" BinaryKey="SetupDLL" DllEntry="readConfigFiles" />

and usage:

<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="ReadConfigFiles" Order="3">1</Publish>

My C++ function looks like this:

extern "C" UINT __stdcall ReadConfigFiles(MSIHANDLE hInstall, CHAR * szDirectory)

Where exactly can I pass in parameters?

+2  A: 

You can't pass parameters directly because in order for this to work, your function has to be exported with exactly the right footprint. When you call readConfigFiles in your custom action dll, it should have a footprint like this:

extern "C" UINT __stdcall readConfigFiles(MSIHANDLE hInstaller);

You can use the hInstaller parameter to read properties from the MSI. Use MsiGetProperty():

HRESULT GetProperty(MSIHANDLE hInstaller, LPCWSTR property, LPWSTR value, DWORD cch_value) {
    UINT err = MsiGetProperty(hInstaller, property, value, &cch_value);
    return (err == ERROR_SUCCESS ? S_OK : E_FAIL);
}

Then just make sure you set the property in your .wxs file:

<Property Id="YOUR-PROPERTY-NAME">your-property-value</Property>
jeffamaphone
)There's a few more in-depth examples out there but a "trick" i found if you don't know length is to call MsiGetProperty with bufferLen = 0, which fails because there isn't enough space to store a value but it also fills bufferLen with how much space is needed to store the actual value. Calling MsiGetProperty again (making sure to allocate value = TCHAR[bufferLen+1] with +1 to make room for a null-terminator) will return the actual value.
glenneroo
Yeah, cch is Microsoft's Hungarian notation for "Count of CHaracters", as opposed to cb which is "Count of Bytes".
jeffamaphone