InnoSetup MsiQueryProductState

I want to replace VS setup with Inno installation. Check if the old version is installed. I found the MsiQueryProductState method. I found several examples similar to:

function MsiQueryProductState(ProductCode: string): integer; external ' MsiQueryProductStateA@msi.dll stdcall'; function MsiConfigureProduct(ProductCode: string; iInstallLevel: integer; eInstallState: integer): integer; external ' MsiConfigureProductA@msi.dll stdcall'; const INSTALLSTATE_DEFAULT = 5; INSTALLLEVEL_MAXIMUM = $ffff; INSTALLSTATE_ABSENT = 2; 

Product verification always returned 2, not the required value 5 (INSTALLSTATE_DEFAULT)

I found an error, I will send it as an answer ...

Thanks freddy

+4
source share
1 answer

The problem was the Unicode InnoSetup version mixed with the prototype version of the ANSI function. This was enough to replace MsiQueryProductStateA with MsiQueryProductStateW .

If you use this conditionally defined script, the InnoSetup compilation preprocessor will find the correct version for the functions (Unicode or ANSI) depending on when you use ANSI or Unicode InnoSetup.

 [Code] #IFDEF UNICODE #DEFINE AW "W" #ELSE #DEFINE AW "A" #ENDIF function MsiQueryProductState(ProductCode: string): integer; external 'MsiQueryProductState{#AW}@msi.dll stdcall'; function MsiConfigureProduct(ProductCode: string; iInstallLevel: integer; eInstallState: integer): integer; external 'MsiConfigureProduct{#AW}@msi.dll stdcall'; 
+4
source

All Articles