Reputation: 693
I want to replace the VS setup by the Inno Setup. Do check if an old version is installed i found the 'MsiQueryProductState' method. I found several examples looking like this:
function MsiQueryProductState(ProductCode: string): integer;
external '[email protected] stdcall';
function MsiConfigureProduct(ProductCode: string;
iInstallLevel: integer; eInstallState: integer): integer;
external '[email protected] stdcall';
const
INSTALLSTATE_DEFAULT = 5;
INSTALLLEVEL_MAXIMUM = $ffff;
INSTALLSTATE_ABSENT = 2;
Checking for the product always returned 2 and not the required 5 value (INSTALLSTATE_DEFAULT)
I found the mistake, I'll post it as an answer ...
Thank Freddy
Upvotes: 4
Views: 2300
Reputation: 693
The problem was the Unicode version of the InnoSetup mixed with the ANSI version of function prototype. It was enough to replace the MsiQueryProductStateA
with MsiQueryProductStateW
.
If you use this conditionally defined script, InnoSetup compilation preprocessor will find the right version for the functions (Unicode or ANSI) depending on when you're using 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';
Upvotes: 4