EXEC using DOS int 21h functions

This is a discussion on EXEC using DOS int 21h functions within the Tech Board forums, part of the Community Boards category; I have been trying to load and execute a .COM file using int 21h DOS interrups (EXEC), but it seems ...

  1. #1
    Registered User albert_sps's Avatar
    Join Date
    Mar 2008
    Location
    Tegucigalpa
    Posts
    6

    Exclamation EXEC using DOS int 21h functions

    I have been trying to load and execute a .COM file using int 21h DOS interrups (EXEC), but it seems there is a problem with the Parameter Block passed to BX. This script executes .COM file but no send parameters properly. Can you help me?

    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <stdlib.h>
    #include <sys\types.h>
    
    int main(int argc, char near *argv[ ])
    {
    int len, i, j, retorna;
    
    union REGS regs;
    
    struct param {
    int segmento;
    int cmd_ptr_offset;
    int cmd_ptr_segment;
    int fcb1_ptr_offset;
    int fcb1_ptr_segment;
    int fcb2_ptr_offset;
    int fcb2_ptr_segment;
    } par;
    
    
    char* cmd;
    struct SREGS sregs;
    
    // argv[3] contain the parameters to the .com   eg. C:\myprogram -e comfilename parameters
    cmd[0] = (char) strlen(argv[3]);
    strcpy(&cmd[1],argv[3]);
    strcat(&cmd[1],"\r");
    
    segread(&sregs);
    
    memset(par, 0, sizeof(par));
    
    par.cmd_ptr_offset = (int) cmd;
    par.cmd_ptr_segment = sregs.ds;
    par.fcb1_ptr_offset = 0x5c;
    par.fcb1_ptr_segment = _psp;
    par.fcb2_ptr_offset = 0x6c;
    par.fcb2_ptr_segment = _psp;
    par.segmento = *((int far *)(((long)_psp<<16) | 0x2c));
    
    
    printf("cmd:%s\n",cmd);
    
    regs.h.ah = 0x4b;
    regs.h.al = 0x00;
    regs.x.dx = (int) argv[2];
    regs.x.bx =(int) &par;
    sregs.es = sregs.ds;
    
    retorna = intdos(&regs,&regs);
    
    if (!(regs.x.cflag ? retorna : 0)) { printf("CARRY FLAG IS CLEAR.\n"); };
    printf("Program has been executed: %s", argv[2]);
    return 0;
    }
    Reference I have used:
    http://www.delorie.com/djgpp/doc/rbinter/id/51/29.html


    Thanks.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    The par struct is a local variable which means it's on the stack. That means it's in SS, not DS. Try changing this line:

    Code:
    sregs.es = sregs.ss;
    EDIT: This thread should be elsewhere...

  3. #3
    Registered User albert_sps's Avatar
    Join Date
    Mar 2008
    Location
    Tegucigalpa
    Posts
    6

    It doesn´t Works :(

    I did changes in line sregs , but its doesn&#180;t works.
    I added lines for alloc/dealloc memory too.

    I&#180;ve tryed differente ways to implement in C++ this (in Basic)
    http://http://www.ethanwiner.com/execute.bas

    Code:
    Regs.ES = VARSEG(Block$)         'segment of parameter block into ES
      Regs.BX = VARPTR(Block$)         'offset of parameter block into BX
      Regs.DS = -1                     'set DS to BASIC's segment
    I get some garbage intead of parameters, in attached example should be ... 123 [Y,N]
    Attached Images Attached Images  
    Last edited by albert_sps; 03-21-2008 at 03:23 PM. Reason: Posting img.

  4. #4
    Registered User albert_sps's Avatar
    Join Date
    Mar 2008
    Location
    Tegucigalpa
    Posts
    6

    Thumbs up

    I changed this line, and to send sregs using intdosx.

    Its working although with some memory garbage outputs.
    Thanks 4 your support Brewbuck
    Last edited by albert_sps; 03-21-2008 at 03:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  4. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 06:34 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21