EXEC using DOS int 21h functions [Archive] - C Board

PDA

View Full Version : EXEC using DOS int 21h functions


albert_sps
03-21-2008, 01:09 AM
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?


#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.

brewbuck
03-21-2008, 10:44 AM
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:


sregs.es = sregs.ss;


EDIT: This thread should be elsewhere...

albert_sps
03-21-2008, 01:37 PM
I did changes in line sregs , but its doesn´t works.
I added lines for alloc/dealloc memory too.

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

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]

albert_sps
03-21-2008, 03:01 PM
I changed this line, and to send sregs using intdosx.

Its working although with some memory garbage outputs.
Thanks 4 your support Brewbuck