2

After reading a lot about how to use dosbox and virtual machines to run older programs on x-64 I found myself in another situation.

I have a 32-bit program that runs correctly, but calls a 16-bit program. So whenever I try to use that function, the program give me the error.

Is it possible to have this program to always run using dosbox? I noticed it works with dosbox, but it should be called from within another program.

references I already read:

Unsupported 16-bit application

Force a program to run on x86?

Error installing program on Windows 7 64-bit

Run 16 bit program on 64 machine bit without dosbox

Run 16 bit program on 64 machine bit without dosbox

running 16-bit code on 64-bit OS, using virtualization

Is it possible to run an old 16-bit DOS application under Windows 7 64-bit?

How do I get 16-bit programs to work on a 64-bit Windows?

Why can't a 64 bit OS run a 16 bit application?


So basically dosbox is an option, but How could I force the program to be run in dosbox whenever it is called?

davejal
  • 553

1 Answers1

0

You can try creating a program that calls it it in DosBox. Then rename the 16-bit executable to progname.old.exe, and rename your new program to progname.exe. Here is an example program (Note: this is untested. It might not even compile.):

#include <stdlib.h>
#include <string.h>
#include <windows.h>

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

    // The string we use to call DOSBOX:
    const char *dosboxstrstart = "path\\to\\dosbox \"path\\to\\progname.old.exe ";
    const char *dosboxstrend = "\" -exit";

    // Get the entire command line, with a full path prepended
    // to the first argument
    char *allcmdline = GetCommandLine();

    // Get a pointer to the start of this program's name, then
    // skip past this program's name to get the arguments only
    char *argstart = strstr(allcmdline, argv[0]) + strlen(argv[0]);

    // Get the length of the argument string
    // Get the length of the DosBox strings
    size_t argstartlen = str_len(argstart);
    size_t dosboxstrstartlen = str_len(dosboxstrstart);
    size_t dosboxstrendlen = str_len(dosboxstrend);

    // Create a buffer for the string to go into (+1 for the \0)
    // Assumes that malloc won't go wrong; a lovely segfault
    // will occur if it does! :-p
    char *finalstring = malloc(argstartlen + dosboxstrstartlen + dosboxstrendlen + 1);

    // Put the string into it, piece by piece
    memcpy(finalstring, dosboxstrstart, dosboxstrstartlen);
    memcpy(finalstring + dosboxstrstartlen, argstart, argstartlen);
    memcpy(finalstring + dosboxstrstartlen + argstartlen, dosboxstrend, dosboxendlen + 1);

    // Run the command
    system(finalstring);

    // Perform our duty to the almighty kernel!
    free(finalstring);
}

This code assumes that the arguments that the 32-bit program passes do not contain quotes. If they do, you'll have to add some sort of escaping function, and I don't know of any in the standard library.

wizzwizz4
  • 749