View Full Version : MsiGetProperty(...): HWND?, pointer?

07-25-2002, 09:16 AM
i got two questions concerning the MsiGetProperty(...) function i want to use in my basic MSI project:

from the docs it says:
* 1st param: MSIHANDLE hInstall // [in] Handle to the installer.
* 4th param: DWORD *pchValueBuf // in/out buffer

so i set up the following function:

function CheckStuff()
NUMBER nvRet; // return value (error codes)
HWND hMyMsi; // handle
STRING szContent; // value of the property
NUMBER nvCount; // in/out: character count
STRING szContent;
nvCount = 0;
//nvRet = MsiGetProperty(hMsi, "MYPUBPROP", szContent; &nvCount); // compile error!
nvRet = MsiGetProperty(hMyMsi, "MYPUBPROP", szContent; nvCount);
//nvRet = MsiGetProperty(0, "MYPUBPROP", szContent; nvCount); // works, too!
SprintfBox(INFORMATION, "MYPUBPROP", " RetVal: %d\n nvCount: %d\n Content: %s", nvRet, nvCount, szContent);

what about the HWND parameter? i guess it's used to retreive the property's value, from. as you can see in my code snippet i'm simply passing an empty handle to the function. but it works! so could someone enlighten me, please, what this parameter is for and whether it is necessary? what further impacts does it have if i just pass it a 0?

what about the fourth parameter? regarding my undestanding it should be "&nvCount", right? but this would result in the error "error C8046: '&' : numeric variable required". any ideas?

cheers, graven (IS dev 7.04)

07-25-2002, 09:35 AM
The first argument is the numeric handle to the running MSI engine. That it uses the HWND data type in InstallScript is misleading; it's a handle, but not a window handle. For an InstallScript custom action you'll want to use the prototype---

export prototype CheckStuff(HWND);
---and then pass the argument to the custom-action function as the first argument to most MSI API functions.

You don't need to use &nBufferSize in InstallScript because the InstallScript prototype of MsiGetProperty uses BYREF NUMBER for that argument. In C, you would need to use &nBufferSize.

07-25-2002, 09:38 AM
The first parameter is the hande to the running MSI. Windows Installer will currently not allow more than 1 setup to run a a time. However they may change that, and you could lauch a child-MSI.

So it may be safer to pass the handle, although is works without one, for future compatibility.

The fourth parameter is the bufferlength for the returning string. Set it to 0, and you'll not get anything usefull.



07-25-2002, 09:58 AM
thanks for the answer, robert.

now i understood there's an installscript wrapper for the MsiGetProperty function.

UINT MsiGetProperty(
MSIHANDLE hInstall, // installer handle
LPCTSTR szName, // property identifier, case-sensitive
LPTSTR szValueBuf, // buffer for returned property value
DWORD *pchValueBuf // in/out buffer character count

/*return type??*/ MsiGetProperty(
STRING(?) szPropertyName,
STRING(?) svPropertyValue,
NUMBER(?) nvBufferSize

the fact is: installscript's "MsiGetProperty" is documented nowhere! that's why i put some question marks in there - and that's where the confusion originated from.

q01 still remains unanswered:
a) what is the ISMSI handle used for?
b) why does it work if i pass it a "0" or an empty HWND?
c) will it do any harm to pass it a "0"?
d) i'm calling my CheckStuff() function inside a basic MSI project - NOT via custom action. just as an internal function. so i might have no handle availabe to pass it to the function. see a), b), c)

cheers, graven (IS dev 7.04)

07-25-2002, 11:46 AM
Using the Search tab in the InstallScript Language Reference returns a couple of pages for MsiGetProperty; as a rule, the MSI functions (like most InstallScript functions) return zero to indicate success.

The first argument is supposed to be a handle to the running MSI engine; I don't know why it works if you pass in zero. (If you're not calling the function from a custom action, how are you calling it?)

07-25-2002, 12:43 PM
i had used the help's search function, without satisfaction. now that i looked once more, i finally found in "Windows Installer API Functions":


// Gets the value of a Windows Installer property.
// Returns a null string ("") if the property does not exist.

> The first argument is supposed to be a handle to the
> running MSI engine; I don't know why it works if you
> pass in zero.

peerke gave some explanation, here. i'm satisfied with that.
i'm just a bit worried that, once i've shipped the setup package, the customer might update his windows installer. maybe the setup won't work any more by passing a "0", then.

(posted by RobertDickau):
> (If you're not calling the function from a custom action,
> how are you calling it?)

well, i'm forcing the basic MSI project to have OnBegin() and OnEnd() executed even though there isn't a single Custom Action used. check this thread for the solution:

cheers, graven (IS dev 7.04)