regEnabled = false;
BOOL initApp(HINSTANCE hInstance, int nCmdShow){  remoteSetProtocol(0);    if(GetDllVersion("comctl32.dll") < PACKVERSION(4,71)) {    systemMessage(0, "Error: COMCTL32.DLL needs to be at least version 4.71");    return FALSE;  }  memset(delta,255, 257*244*2);  systemVerbose = GetPrivateProfileInt("config",                                       "verbose",                                       0,                                       "VBA.ini");    systemDebug = GetPrivateProfileInt("config",                                     "debug",                                     0,                                     "VBA.ini");  ddrawDebug = GetPrivateProfileInt("config",                                    "ddrawDebug",                                    0,                                    "VBA.ini");  joyDebug = GetPrivateProfileInt("config",                                  "joyDebug",                                  0,                                  "VBA.ini");    WNDCLASS                    wc;   // Set up and register window class  wc.style = CS_HREDRAW | CS_VREDRAW;  wc.lpfnWndProc = WindowProc;  wc.cbClsExtra = 0;  wc.cbWndExtra = 0;  wc.hInstance = hInstance;  wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON));  wc.hCursor = LoadCursor(NULL, IDC_ARROW);  wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);  wc.lpszMenuName = "GBA";  wc.lpszClassName = "GBA";  RegisterClass(&wc);  ::hInstance = hInstance;  ::nCmdShow = nCmdShow;  arrow = LoadCursor(NULL, IDC_ARROW);  GetModuleFileName(NULL, winBuffer, 2048);  char *p = strrchr(winBuffer, '\\');  if(p)    *p = 0;    regInit(winBuffer);  regEnabled = regQueryDwordValue("regEnabled", 1, true) ?    true : false;  if(regEnabled) {    regSetDwordValue("regEnabled", false);    regExportSettingsToINI();    systemMessage(IDS_REGISTRY, "VisualBoyAdvance no longer uses the registry."                  " Your settings were exported to file: %s", regGetINIPath());  }    languageOption = regQueryDwordValue("language", 1);  if(languageOption < 0 || languageOption > 2)    languageOption = 1;  char *lang = regQueryStringValue("languageName", NULL);  if(lang) {    strncpy(languageName, lang, 4);    languageName[3] = 0;  } else    languageName[0] = 0;    winSetLanguageOption(languageOption, true);    frameSkip = regQueryDwordValue("frameSkip", 2);  if(frameSkip < 0 || frameSkip > 9)    frameSkip = 2;  gbFrameSkip = regQueryDwordValue("gbFrameSkip", 0);  if(gbFrameSkip < 0 || gbFrameSkip > 9)    gbFrameSkip = 0;  autoFrameSkip = regQueryDwordValue("autoFrameSkip", FALSE) ? TRUE : FALSE;    vsync = regQueryDwordValue("vsync", 0);  synchronize = regQueryDwordValue("synchronize", 1) ? true : false;  fullScreenStretch = regQueryDwordValue("stretch", 0) ? true : false;  videoOption = regQueryDwordValue("video", 0);  if(videoOption < 0 || videoOption > VIDEO_OTHER)    videoOption = 0;  BOOL defaultVideoDriver = regQueryDwordValue("defaultVideoDriver", TRUE) ?    TRUE : FALSE;  if(!regQueryBinaryValue("videoDriverGUID", (char *)&videoDriverGUID,                          sizeof(GUID))) {    defaultVideoDriver = TRUE;  }  if(defaultVideoDriver)    pVideoDriverGUID = NULL;  else    pVideoDriverGUID = &videoDriverGUID;  fsWidth = regQueryDwordValue("fsWidth", 0);  fsHeight = regQueryDwordValue("fsHeight", 0);  fsColorDepth = regQueryDwordValue("fsColorDepth", 0);  if(videoOption == VIDEO_OTHER) {    if(fsWidth < 0 || fsWidth > 4095 || fsHeight < 0 || fsHeight > 4095)      videoOption = 0;    if(fsColorDepth != 16 && fsColorDepth != 24 && fsColorDepth != 32)      videoOption = 0;  }  renderMethod = (DISPLAY_TYPE)regQueryDwordValue("renderMethod", DIRECT_DRAW);  if(renderMethod < GDI || renderMethod > OPENGL)    renderMethod = DIRECT_DRAW;    windowPositionX = regQueryDwordValue("windowX", 0);  if(windowPositionX < 0)    windowPositionX = 0;  windowPositionY = regQueryDwordValue("windowY", 0);  if(windowPositionY < 0)    windowPositionY = 0;  useBiosFile = regQueryDwordValue("useBios", 0) ? true: false;  skipBiosFile = regQueryDwordValue("skipBios", 0) ? true : false;  char * c = regQueryStringValue("biosFile", NULL);  if(c) {    strcpy(biosFileName, c);  }    int res = regQueryDwordValue("soundEnable", 0x30f);    soundEnable(res);  soundDisable(~res);  soundOffFlag = (regQueryDwordValue("soundOff", 0)) ? true : false;  soundQuality = regQueryDwordValue("soundQuality", 2);  soundEcho = regQueryDwordValue("soundEcho", 0) ? true : false;  soundLowPass = regQueryDwordValue("soundLowPass", 0) ? true : false;  soundReverse = regQueryDwordValue("soundReverse", 0) ? true : false;  soundVolume = regQueryDwordValue("soundVolume", 0);  if(soundVolume < 0 || soundVolume > 3)    soundVolume = 0;  ddrawEmulationOnly = regQueryDwordValue("ddrawEmulationOnly", 0);  ddrawUseVideoMemory = regQueryDwordValue("ddrawUseVideoMemory", 0);  tripleBuffering = regQueryDwordValue("tripleBuffering", TRUE) ? TRUE : FALSE;  d3dFilter = regQueryDwordValue("d3dFilter", 0);  if(d3dFilter < 0 || d3dFilter > 1)    d3dFilter = 0;  glFilter = regQueryDwordValue("glFilter", 0);  if(glFilter < 0 || glFilter > 1)    glFilter = 0;  glType = regQueryDwordValue("glType", 0);  if(glType < 0 || glType > 1)    glType = 0;  filterType = regQueryDwordValue("filter", 0);  if(filterType < 0 || filterType > 11)    filterType = 0;  disableMMX = regQueryDwordValue("disableMMX", 0) ? true: false;  disableStatusMessage = regQueryDwordValue("disableStatus", 0) ? true : false;  showSpeed = regQueryDwordValue("showSpeed", 1);  if(showSpeed < 0 || showSpeed > 2)    showSpeed = 1;  showSpeedTransparent = regQueryDwordValue("showSpeedTransparent", TRUE) ?    TRUE : FALSE;  winGbPrinterEnabled = regQueryDwordValue("gbPrinter", 0);  if(winGbPrinterEnabled)    gbSerialFunction = gbPrinterSend;  else    gbSerialFunction = NULL;    pauseWhenInactive = regQueryDwordValue("pauseWhenInactive", 1) ?    true : false;  useOldSync = regQueryDwordValue("useOldSync", 0) ?    TRUE : FALSE;  captureFormat = regQueryDwordValue("captureFormat", 0);  removeIntros = regQueryDwordValue("removeIntros", 0);  recentFreeze = regQueryDwordValue("recentFreeze", 0);  autoIPS = regQueryDwordValue("autoIPS", 1);  cpuDisableSfx = regQueryDwordValue("disableSfx", 0) ? true : false;    winSaveType = regQueryDwordValue("saveType", 0);  if(winSaveType < 0 || winSaveType > 5)    winSaveType = 0;    cpuEnhancedDetection = regQueryDwordValue("enhancedDetection", 1) ? true :    false;  ifbType = regQueryDwordValue("ifbType", 0);  if(ifbType < 0 || ifbType > 2)    ifbType = 0;  winFlashSize = regQueryDwordValue("flashSize", 0x10000);  if(winFlashSize != 0x10000 && winFlashSize != 0x20000)    winFlashSize = 0x10000;  agbPrintEnable(regQueryDwordValue("agbPrint", 0) ? true : false);  winRtcEnable = regQueryDwordValue("rtcEnabled", 0) ? true : false;  rtcEnable(winRtcEnable);  autoHideMenu = regQueryDwordValue("autoHideMenu", 0) ? true : false;  skinEnabled = regQueryDwordValue("skinEnabled", 0) ? true : false;  skinName = regQueryStringValue("skinName", "");  switch(videoOption) {  case VIDEO_320x240:    fsWidth = 320;    fsHeight = 240;    fsColorDepth = 16;    break;  case VIDEO_640x480:    fsWidth = 640;    fsHeight = 480;    fsColorDepth = 16;    break;  case VIDEO_800x600:    fsWidth = 800;    fsHeight = 600;    fsColorDepth = 16;    break;  }    if(!initDisplay()) {    if(videoOption >= VIDEO_320x240) {      regSetDwordValue("video", VIDEO_1X);      if(pVideoDriverGUID)        regSetDwordValue("defaultVideoDriver", TRUE);    }    return FALSE;  }  if(!initDirectInput())    return FALSE;  winReadKeys();  if(regQueryDwordValue("joyVersion", 0) == 0) {    convertKeys();  }  checkKeys();  joypadDefault = regQueryDwordValue("joypadDefault", 0);  if(joypadDefault < 0 || joypadDefault > 3)    joypadDefault = 0;  hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));  winAccelMgr.Connect(hWindow);  winAccelMgr.SetRegKey(HKEY_CURRENT_USER, "Software\\Emulators\\VisualBoyAdvance");  extern void winAccelAddCommands(CAcceleratorManager&);  winAccelAddCommands(winAccelMgr);  winAccelMgr.CreateDefaultTable();  winAccelMgr.Load();  winAccelMgr.UpdateWndTable();  char buffer[50];    for(int i = 0; i < 10; i++) {    sprintf(buffer, "recent%d", i);    char *s = regQueryStringValue(buffer, NULL);    if(s == NULL)      break;    recentFiles[i] = strdup(s);  }    winGbBorderOn = regQueryDwordValue("borderOn", 0);  gbBorderAutomatic = regQueryDwordValue("borderAutomatic", 0);  gbEmulatorType = regQueryDwordValue("emulatorType", 1);  if(gbEmulatorType < 0 || gbEmulatorType > 5)    gbEmulatorType = 1;  gbColorOption = regQueryDwordValue("colorOption", 0);  threadPriority = regQueryDwordValue("priority", 2);  if(threadPriority < 0 || threadPriority >3)    threadPriority = 2;  updatePriority();  autoSaveLoadCheatList = regQueryDwordValue("autoSaveCheatList", 0) ?    true : false;  gbPaletteOption = regQueryDwordValue("gbPaletteOption", 0);  if(gbPaletteOption < 0)    gbPaletteOption = 0;  if(gbPaletteOption > 2)    gbPaletteOption = 2;  regQueryBinaryValue("gbPalette", (char *)systemGbPalette,                      24*sizeof(u16));  rewindTimer = regQueryDwordValue("rewindTimer", 0);  if(rewindTimer < 0 || rewindTimer > 600)    rewindTimer = 0;  rewindTimer *= 6; // convert to 10 frames multiple    if(rewindTimer != 0)    rewindMemory = (char *)malloc(8*REWIND_SIZE);  return TRUE;}