GetNativeSystemInfo worked. Thanks!

The code ended being like this (it seems to be working both in x86 and x86_64):

import std.file: exists, getcwd;
import std.path: buildPath, dirName;
import std.string: format, toStringz;
import core.sys.windows.windows;

enum X86   = 0;
enum AMD64 = 9;
immutable static auto appname = "myapp";

extern(Windows) HANDLE ShellExecuteA(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, int);
extern(Windows) int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT);

int main() {
  auto appath = getcwd();
  string appexe;
  SYSTEM_INFO env;
  GetNativeSystemInfo(&env);
  switch(env.wProcessorArchitecture) {
    case X86: appexe = buildPath(appath, appname ~ "32.exe"); break;
    case AMD64: appexe = buildPath(appath, appname ~ "64.exe"); break;
    default:
MessageBoxA(null, "System architecture is not supported.", "Error", MB_ICONHAND + MB_OK);
      return -1;
  }
  if (exists(appexe)) {
auto param = format(`/ini="%s"`, buildPath(appath, appname ~ ".ini")); ShellExecuteA(null, "", toStringz(appexe), toStringz(param), "", SW_SHOWMAXIMIZED);
    scope(failure) return -2;
  }
  return 0;
}

Reply via email to