4

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 '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;

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

Freddy
  • 693
  • 2
  • 6
  • 12
  • 2
    If you find the solution yourself, you should post it as an answer. You can then mark it as accepted a few hours later. – Deanna Oct 07 '11 at 09:16

1 Answers1

4

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';
TLama
  • 75,147
  • 17
  • 214
  • 392
Freddy
  • 693
  • 2
  • 6
  • 12
  • +1, I've extended your answer with a little trick (originally founded by [kobik](http://stackoverflow.com/users/937125/kobik) [here](http://stackoverflow.com/a/9670505/960757)). Could you review my edit and optionally rollback if you don't like it ? Thanks! – TLama Jun 29 '12 at 03:12