Stability on target PC's

Blitz3D Forums/Blitz3D Bug Reports/Stability on target PC's

// Here's a C program that I'm using as a work-around


// Fixup for B3D / Microsoft compatability
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <io.h>
#include <process.h>
#include <time.h>

#define TARGET_PROGRAM "_.exe"
#define COMMAND_LINE " test"
// Note the use of a space at the beginning of the command line

int RunAndWait(char *startup, char *ex, char *cl)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);

// Start the child process.
if(CreateProcess(ex, // module name
cl, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
startup, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
== 0)
{
MessageBox(NULL, ex, "Error: Cannot run!", MB_OK);
return(0);
}

WaitForInputIdle( pi.hProcess, INFINITE );
SetCursor(LoadCursor(NULL, IDC_ARROW));
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return(1);
}


BOOL DisableAdvText(char *FileName)
{
HKEY hkey;
DWORD dw;
static char Val[] = "DISABLECICERO";

RegOpenKeyEx(HKEY_CURRENT_USER,"",0,KEY_QUERY_VALUE,&hkey);
RegCreateKeyEx (hkey, "Software", 0L, NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL, &hkey, &dw);
RegCreateKeyEx (hkey, "Microsoft", 0L, NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,&hkey, &dw);
RegCreateKeyEx (hkey, "Windows NT", 0L, NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,&hkey, &dw);
RegCreateKeyEx (hkey, "CurrentVersion", 0L, NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,&hkey, &dw);
RegCreateKeyEx (hkey, "AppCompatFlags", 0L, NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,&hkey, &dw);
RegCreateKeyEx (hkey, "Layers", 0L, NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,&hkey, &dw);
RegSetValueEx(hkey, FileName, 0, REG_SZ, (const BYTE*)Val, sizeof(Val) + 1);
RegFlushKey(hkey);
RegCloseKey(hkey);
return TRUE;
}

BOOL EnableAdvText(char *FileName)
{
HKEY hkey;
RegOpenKeyEx(HKEY_CURRENT_USER,"",0,KEY_QUERY_VALUE,&hkey);
RegOpenKeyEx(hkey,"Software",0,KEY_QUERY_VALUE,&hkey);
RegOpenKeyEx(hkey,"Microsoft",0,KEY_QUERY_VALUE,&hkey);
RegOpenKeyEx(hkey,"Windows NT",0,KEY_QUERY_VALUE,&hkey);
RegOpenKeyEx(hkey,"CurrentVersion",0,KEY_QUERY_VALUE,&hkey);
RegOpenKeyEx(hkey,"AppCompatFlags",0,KEY_QUERY_VALUE,&hkey);
RegOpenKeyEx(hkey,"Layers",0,KEY_SET_VALUE,&hkey);
RegDeleteValue(hkey, FileName);
RegFlushKey(hkey);
RegCloseKey(hkey);
return TRUE;
}

int MutexExists(char *pMutexName)
{
// Attempt to create defualt mutex owned by process
CreateMutex(NULL, 1, pMutexName);

// Check success
if (GetLastError() == ERROR_ALREADY_EXISTS)
// Mutex was not created
return 1;
else
// Mutex was created
return 0;
}

// WinMain - main routine.
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
char TheFile[256];
char folder[256];
char combuff[256];
// Check for previous instance of application
if(MutexExists("B3D Fix"))
{
// Display error message
MessageBox(NULL, "I'm already running!", "Error", MB_OK | MB_ICONERROR);
// Close current instance
return 0;
}

GetCurrentDirectory(sizeof(folder), folder);
strcpy(TheFile, folder);
strcat(TheFile, "\\");
strcat(TheFile, TARGET_PROGRAM);
DisableAdvText(TheFile);
strcpy(combuff, TARGET_PROGRAM);
strcat(combuff, COMMAND_LINE);
RunAndWait(folder, TheFile, combuff);
EnableAdvText(TheFile);
return(0L);
}