home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <conio.h>
-
-
-
- typedef unsigned int BOOL;
- typedef unsigned int WORD;
- typedef unsigned long DWORD;
- #define FAR _far
-
-
- int WinExec(unsigned long vxd_api, char *pname,
- char *argname, int show_num, BOOL validate);
-
-
- /*
-
- This works fine with Borland C, version 3.1 compiled with small model.
-
- It should work ok with other memory models and except for libray function
- calls it might work with microsoft.
-
-
- */
-
-
-
- char badexec_msg[] = { "\nTSTWINEX: failed to load windows application\n" };
-
- unsigned long GetVxDAPI(void);
-
- main( int argc, char **argv)
- {
- int result = 0;
- char show_type[5];
- int show_num;
- unsigned long vxd_api;
- unsigned int len;
-
- char Prog_line[128];
-
-
- char Arg_line[128];
-
-
-
-
- vxd_api = GetVxDAPI(); // returns a seg:offset, pointer in a long
- if(!vxd_api) goto noesdi;
-
-
- fputs("\nEnter program name: ", stdout);
- fgets(Prog_line, sizeof(Prog_line)-1, stdin); // delete trailing \r
- len = strlen(Prog_line);
- if(len)
- Prog_line[len-1] = 0;
-
- // strcpy(Prog_line, "G:\\win31\\clock.exe");
-
-
- fputs("\nEnter program args: ", stdout);
- fgets(Arg_line, sizeof(Arg_line), stdin);
-
- len = strlen(Arg_line);
- if(len)
- Arg_line[len-1] = 0;
-
- new_num:
-
- fputs("\nEnter Show Type: ", stdout);
- fgets(show_type, 2, stdin);
- show_type[strlen(show_type)] = 0;
-
-
-
- show_num = atoi(show_type);
- if((show_num < 0) || (show_num > 9)) {
- fputs("\nNot a legal show number (0-9)\n", stdout);
- goto new_num;
- }
-
- // the args: Prog_line and Arg_line are zero terminated, normal c strings
-
- result = WinExec(vxd_api, Prog_line, Arg_line, show_num, 0);
-
-
- if(result == -1) goto err;
- if(result > 32-1) goto ok;
-
- fputs(badexec_msg,stdout);
-
-
- goto ok;
- noesdi:
- fputs("TESTPRI error: Can't run without EDOS & Windows\n", stdout);
- return 1;
-
- err:
-
- printf("%s \n", "Error: TstWinexe failed");
- getch();
- return 1;
- ok:
-
- return result;
- }
-
- unsigned long GetVxDAPI(void)
- {
-
- #define EDOS_ID 0x2925
-
- unsigned long vxd_api;
- _asm {
-
- push es
- mov di,0 // make sure es,di are set to zero
- mov es,di
- mov ax,0x1684 // the int 2f call number
-
- mov bx,EDOS_ID // edos VxD ID number
-
- int 0x2f
- mov word ptr [vxd_api+2],es // segment of v86 entry point in edos
- mov word ptr [vxd_api],di // offset of entry point
- mov ax,es
- or ax,di
- pop es
- mov al,10
- jz noesdi
- }
- return vxd_api;
-
- noesdi:
- return 0L;
-
- }
-
-
-
-
- int WinExec(
- unsigned long vxd_api, // the entry point of the edos v86 api
- char *pname, // the program to run, far pointer, maxlen=128
- char *argname, // the argument string, far pointer, maxlen=127
- int show_num, // SW_NORMAL, type number
- BOOL validate // do extra validation, not implemented yet
- )
-
- {
-
- typedef struct {
- WORD seg_env;
- WORD off_arg;
- WORD seg_arg;
- WORD Shownum; //off_fcb;
- WORD seg_fcb;
- DWORD dummy;
-
- } exec_block;
-
-
- unsigned int len;
- exec_block parm;
-
- char Arg_line[128+6];
- char FAR *arg_fptr, FAR *name_fptr;
- char *arg_ptr;
- int retval;
-
-
- parm.seg_env = 0; // clear the parm block
- parm.off_arg = 0;
- parm.seg_arg = 0;
- parm.Shownum = 0;
- parm.seg_fcb = 0;
- parm.dummy = 0L;
-
- Arg_line[0] = 0; // first byte of line contains the len, init to 0
- arg_ptr = (char *)Arg_line;
- arg_ptr++; // make sure we point past the len byte
-
- arg_fptr = (char FAR*)Arg_line; // make a far pointer to the arg line
- parm.off_arg = FP_OFF(arg_fptr);
- parm.seg_arg = FP_SEG(arg_fptr);
-
- strcpy(arg_ptr, argname); // add the real arg data string
- len = strlen(arg_ptr); // get it's length
-
- // len > 127 problems
-
-
- Arg_line[0] = len; // finish making the final arg line
- arg_ptr[len] = 13; // adde carriage return
- arg_ptr[len+1]= 0; // make sure the line is zero terminated
-
-
- arg_fptr = (char FAR*)&parm;
-
- parm.seg_fcb = (WORD)FP_SEG(arg_fptr);
-
- name_fptr = (char FAR *)pname;
-
-
- // max len of pname and arg_line strings combined is 128
-
-
- _asm {
-
- les bx, ss:[arg_fptr]
- // these 3 variable names are ASSUMED to be on the stack
-
- lds dx, ss:[name_fptr]
-
- mov cx, ss:[show_num]
-
- mov ax,3 //; exec windows app function call
-
- call vxd_api
-
- cmp ax, -1 // be sure didn't get original 3
- jne err
-
- cmp bx, 32 // bx = the handle returned from WinExec
- mov retval,bx
- jg ok
- mov retval,bx
- }
- return retval;
-
-
- err:
- return -1;
-
- ok:
- return retval;
-
- }
-