开发者

InnoSetup MsiQueryProductState

开发者 https://www.devze.com 2023-04-11 03:46 出处:网络
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 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 s开发者_如何转开发tdcall';
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


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

精彩评论

暂无评论...
验证码 换一张
取 消