Deploying Windows applications on Linux(Wine) with InnoSetup

First, we need to detect Wine in the InnoSetup script.

function LoadLibraryA(lpLibFileName: PAnsiChar): THandle;
external 'LoadLibraryA@kernel32.dll stdcall';
function GetProcAddress(Module: THandle; ProcName: PAnsiChar): Longword;
external 'GetProcAddress@kernel32.dll stdcall';

function IsWine: boolean;
var  LibHandle  : THandle;
begin
  LibHandle := LoadLibraryA('ntdll.dll');
  Result:= GetProcAddress(LibHandle, 'wine_get_version')<> 0;
end;

The IsWine function returns true, if the installer is launched under Wine. My application (Image Uploader) is extensively using Microsoft Gdi+ library, but Wine's implementation of this library is incomplete, so I had no other choice but to install the native version of gdiplus.dll. The important thing is to tell Wine to use the native library instead of the built-in one, it can be achieved by writing a setting to the Wine's registry.

procedure CurStepChanged(CurStep: TSetupStep);
begin
 if  CurStep=ssPostInstall and IsWine   then
  begin
     filecopy(expandconstant('{tmp}\gdiplus.dll'),expandconstant('{app}\gdiplus.dll'),false);

     RegWriteStringValue(HKEY_CURRENT_USER, 'Software\Wine\DllOverrides',
    'gdiplus', 'native, builtin');
 end;
end;

There are some other issues when Image Uploader is running in Wine, for example, Wine is ignoring WM_CTLCOLORSTATIC message's result, also Richedit's EM_FORMATRANGE is not working. But I hope I'll find a workaround for these issues too.