Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

retrieving TARGETDIR or INSTALLDIR from a custom action dll

668 views
Skip to first unread message

oregonduckman

unread,
Oct 15, 2007, 2:23:00 PM10/15/07
to
I have implemented a custom action dll to respond to Install/Uninstall
actions and am trying to retrieve TARGETDIR or INSTALLDIR from the msi
wrapper. I have tried the following with no success, any advice would be
appreciated:

hModule was passed via DllMain

PMSIHANDLE hDatabase = MsiGetActiveDatabase(hModule);
UINT u = MsiGetProperty(hModule, "INSTALLDIR",buffer,&cch);

and

MsiGetTargetPath(hModule, "INSTALLDIR",buffer,&cch);

Thanks

Phil Wilson

unread,
Oct 15, 2007, 3:38:34 PM10/15/07
to
You should be calling MsiGetProperty on the MSIHANDLE passed into the custom
action. That should just work, keeping in mind that deferred custom actions
need to use the CustomActionData indirection.
--
Phil Wilson
[MVP Windows Installer]

"oregonduckman" <oregon...@discussions.microsoft.com> wrote in message
news:532140F2-0822-406F...@microsoft.com...

oregonduckman

unread,
Oct 15, 2007, 4:28:03 PM10/15/07
to
Here is the code I am using which always returns 0. I am using the Install
entry point passing [TARGETDIR] as the CustomActionData.

char cReturn[MAX_PATH] = {0};
char buffer[MAX_PATH] = {0};
DWORD dwLength = MAX_PATH;
UINT u = MsiGetProperty(hModule, "[TARGETDIR]",buffer,&dwLength);

Phil Wilson

unread,
Oct 15, 2007, 8:20:11 PM10/15/07
to
If this is a deferred custom action you don't get TARGETDIR, you get the
"CustomActionData" property, and that mechanism requires a previous custom
action (typically with a type 51) that sets the name of the custom action to
the property that will become the CustomActionData property. Also, because
you're explicitly getting properties you don't need the square brackets
around the name.

--
Phil Wilson
[MVP Windows Installer]


"oregonduckman" <oregon...@discussions.microsoft.com> wrote in message

news:8B741E46-A00F-43DB...@microsoft.com...

Christopher Painter

unread,
Oct 15, 2007, 9:21:30 PM10/15/07
to
You may also find that frequently you need to access multiple
properties during the deferred execution. One common practice is to
serialize and deserialize the properties and values. XML would be
great for this ( think SOAP ) but it adds another dependency to the
install.

For a simple example of this in InstallScript, checkout:

http://www.installsite.org/pages/en/msi/ca.htm

Porting it to C++ shouldn't be too difficult.

oregonduckman

unread,
Oct 15, 2007, 9:49:02 PM10/15/07
to
Found the constant IPROPNAME_CUSTOMACTIONDATA which did the trick. The msi
docs seem to be all over the place can you recommend a book that give good
examples in a C++ environment?

Thanks for your help on this.

Christopher Painter

unread,
Oct 15, 2007, 10:23:55 PM10/15/07
to
You could look at the WiXCA(.dll) source in WiX.


Christopher Painter

unread,
Oct 15, 2007, 11:57:24 PM10/15/07
to
No, CustomActionData is literally [CustomActionData]

Type 51 CA MyCustomAction_CAD MyCustomAction [TARGETDIR] //
Immeadiate execution. Format [TARGETDIR] and assign it to the
property MyCustomAction
Type 1 CA: MyCustomAction Deferred NoImpersonation Msi Standard
Call DFF

When MyCustomAction is running access CustomActionData to see the
formatted value of [TARGETDIR]

For examples in InstallScript, see my article:

http://www.installsite.org/pages/en/msi/ca.htm ( Decode the
CustomActionData property in InstallScript )

Phil Wilson

unread,
Oct 16, 2007, 10:45:22 AM10/16/07
to
Right, but in his C++ code he was asking for the property name including the
brackets, that's what I was referring to.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
"Christopher Painter" <chr...@yahoo.com> wrote in message
news:1192495544....@z24g2000prh.googlegroups.com...

Christopher Painter

unread,
Oct 16, 2007, 12:49:26 PM10/16/07
to
> > CustomActionData property in InstallScript )- Hide quoted text -
>
> - Show quoted text -

Sorry Phil, Google posted that message out of sequence. I was
replying to the OP not you. You are correct, in this context the API
already knows it's being given a property name as an argument. In the
case of Formattable types/API's you would need brackets.

0 new messages