how to detect OS architecture?
Hugo Florentino
hugo at acdam.cu
Mon Dec 16 13:22:45 PST 2013
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;
}
More information about the Digitalmars-d-learn
mailing list