Jump to content
LaunchBox Community Forums

configuration application always runs with built-in DOSBox


Matthew Noel

Recommended Posts

I Have a custom DOSBox version set for all my MS-DOS games (DOSBos-X), but when I try to run a configuration application for a game it uses built-in DOSBox 0.74. Also the "Open DOSBox..." menu option is the same. It's important to run the config programs in the same DOSBox as the game itself, especially if it lets you test or auto-detect hardware.

Link to comment
Share on other sites

My workaround for this is so dumb. Please help.

I made a custom EXE that just redirects to DOSBox-x and overwrote the built-in one. Yes, I know I could just put DOSBox-x in the built-in folder and rename the EXE, but I'm stubborn.

Here's the code if anyone's interested:

Spoiler

#include <cstring>
#include <Windows.h>

bool hasSpace(char *str) {
	while (*str != 0) {
		if (*str == ' ') {
			return true;
		}
		str++;
	}
	return false;
}

int main(int argc, char *argv[]) {

	char *command = static_cast<char *>(malloc(32767));

	memset(command, 0, 32767);

	strcat_s(command, 32767, "dosbox-x.bat");

	for (int i = 1; i < argc; ++i) {
		strcat_s(command, 32767, " ");

		if (hasSpace(argv[i])) {
			strcat_s(command, 32767, "\"");
			strcat_s(command, 32767, argv[i]);
			strcat_s(command, 32767, "\"");
		} else {
			strcat_s(command, 32767, argv[i]);
		}
	}


	// additional information
	STARTUPINFOA        si;
	PROCESS_INFORMATION pi;

	// set the size of the structures
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	ZeroMemory(&pi, sizeof(pi));

	// start the program up
	if (!CreateProcess
			(
					R"(..\..\..\DOSBox-X\0.83.6\bin\x64\Release SDL2\dosbox-x.bat)", // Path to executable
					command,                                            // Command line
					nullptr,                                            // Process handle not inheritable
					nullptr,                                            // Thread handle not inheritable
					FALSE,                                              // Set handle inheritance to FALSE
					INHERIT_CALLER_PRIORITY,                            // Inherit parent's priority
					nullptr,                                            // Use parent's environment block
					R"(..\..\..\DOSBox-X\0.83.6\bin\x64\Release SDL2)", // Starting directory
					&si,                                                // Pointer to STARTUPINFO structure
					&pi                                                 // Pointer to PROCESS_INFORMATION
			)) {
		// Close process and thread handles.
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);

		return 1;
	}

	free(command);

	auto exitcode = STILL_ACTIVE;
	while (exitcode == STILL_ACTIVE) {
		WaitForSingleObject(pi.hProcess, INFINITE);
		GetExitCodeProcess(pi.hProcess, &exitcode);
	}

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

	return exitcode;
}

 

EDIT: Code cleanup.

Edited by Matthew Noel
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...