home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
DOSSWT.ZIP
/
DOSSWTCH.C
Wrap
Text File
|
1991-07-10
|
4KB
|
146 lines
/************************************************************************
* Originally Taken from DOSSYS.C by Peter Fitzsimmons. Code fragment
* of PM application. The command line to pass to the DOS box is passed
* to Launch_Dos and written to the DOS.SYS device driver for execution.
*
* Changes to jump2dos by Bryan Walker, Memphis Tn. instructing PM to
* return your PM application back to foreground after DOS App. is done.
************************************************************************/
VOID Launch_Dos(CHAR *cmd)
{
HFILE hf;
USHORT rc, dummy;
int i;
/**************
* Open Dos.sys and write the command line
* desired. I usually use a batch file so that
* a short command line accomplishes several
* functions. Useful for launching a DOS based
* report writer such as Clipper against data
* gathered into a DB3 compatible database.
**************/
rc = DosOpen("DOS$", &hf, &dummy, 0L, FILE_NORMAL, FILE_OPEN,
OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE |
OPEN_FLAGS_FAIL_ON_ERROR, 0L);
if(!rc)
{
rc = DosWrite(hf, cmd, strlen(cmd)+1, &dummy);
DosClose(hf);
if(!rc)
jump2dos(); //successfully opened DOS.sys and wrote command
else if(rc == ERROR_NOT_READY)
{
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
"A program is already running in the DOS box",
"Reports", 0, MB_OK|MB_ICONEXCLAMATION);
return;
}
else
{
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
"Unexpected OS/2 error",
"Reports", 0, MB_OK|MB_ICONEXCLAMATION);
return;
}
}
else
{
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
"DOS.SYS not installed",
"Reports", 0, MB_OK|MB_ICONEXCLAMATION);
return;
}
}
void jump2dos(void)
{
USHORT num, i;
void *buf = malloc(32000);
SWENTRY *swe;
HSWITCH fgHandle;
SEL selGlobalSeg, selLocalSeg;
GINFOSEG FAR * volatile pgis;
UCHAR sgDos;
/*****************************************
* Here is where we get the Switch handle
* for our application. The Window Handle
* hwndFrame is for the frame of this PM
* application. When the DOS app is complete
* switching back to this switch handle
* will bring our app back to the foreground.
*
* The original code got the switch handle for
* the current foreground application which may
* not match our app. but instead be the Task List.
* Getting the switch handle for our app insures
* that it will be in the foreground when DOS
* finishes, even if it weren't when we started
* DOS.
*******************************************/
DosGetInfoSeg(&selGlobalSeg, &selLocalSeg);
pgis = MAKEPGINFOSEG(selGlobalSeg);
fgHandle = WinQuerySwitchHandle(hwndFrame, 0); //Switch handle
/* Find the switch list handle of the DOS box: */
num = WinQuerySwitchList(0L, buf, 32000);
swe = (SWENTRY *)((USHORT *)buf + 1);
for(i=0; i<num; i++)
{
if(!strcmp("DOS", swe[i].swctl.szSwtitle))
{
WinSwitchToProgram(swe[i].hswitch);
break;
}
}
free(buf);
if(i==num)
{
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
"CANNOT Run Reports\nThis system is configured without a dos box!",
"Reports", 0, MB_OK|MB_ICONEXCLAMATION);
return;
}
if(fgHandle)
{
DosSleep(1000L); /* give a moment for the task switch */
sgDos = pgis->sgCurrent;
/* Peter Fitzsimmons' Comment (BCW)
* Wait (poll) current screen group -- waiting for the DOS
* program to end. I don't like polling, but this is the only
* solution I can come up with. If you don't mind the "Task
* List" always being brought the the fore after the dos progam
* ends, you can forget about all of this and exit() after the
* WinSwitchToProgram(), above.
*/
while( sgDos == pgis->sgCurrent )
DosSleep(500L);
WinSwitchToProgram(fgHandle); /* back to our PM Program */
}
}