ID Number: Q74887
3.00
WINDOWS
Summary:
It is possible to create a Windows application that can be started
directly from the DOS prompt. For example, the KILLERAP application
may be written so that when KILLERAP is typed at the DOS prompt,
Windows is loaded and KILLERAP run.
However, some specific programming is required to perform this task.
Otherwise, enhanced mode Windows will produce a "Memory Segmented"
error message. This article discusses the techniques required.
More Information:
The "Memory Segmented" error message is caused by the fact that the
application that spawns Windows remains in memory when Windows loads.
There is a straightforward way to work around this complication.
Replace the standard WINSTUB.EXE program, provided with the Windows
Software Development Kit, with a custom program tailored to the
application.
The following sample WINSTUB program loads the string "win notepad"
into the keyboard key buffer. Then the program terminates and is
removed from memory. The keystrokes in the key buffer are played back
by the hardware to DOS. This starts Windows and runs the program.
This sample code requires Microsoft C version 6.0 or later to compile
because it uses inline assembly code. A similar program may be written
with the Microsoft Macro Assembler (MASM) version 5.1 or later.
Sample Code
-----------
void main(void)
{
char szExecLine[] = "win notepad\r";
int iIndex;
char cChar;
for (iIndex = 0; iIndex < sizeof(szExecLine); iIndex++)
{
cChar = szExecLine[iIndex];
_asm
{
mov ah, 05h
mov ch, 0
mov cl, cChar
int 16h
}
}
}