At bytes 44 and 45 of the PSP, you'll find an unsigned integer that's equal to the segment address of the environment block. To examine the block, you'll need to convert this segment pointer to either a far or a huge pointer.
Since the environment block is a group of text strings, you can
use something like
char _far* envPtr = *((char _seg **)envSegAddress);
Here, envSegAddress is the unsigned integer value from bytes 44 and 45 of the PSP. We cast this value as a segment pointer to a character pointer with (char _seg **).
Finally, we dereference this pointer to get a segment pointer to a character, and we assign the new segment pointer to the far pointer envPtr. (Borland C++ will automatically convert the segment pointer to a far pointer before the assignment.)
Once you have this pointer, you can examine your program's copy of the environment block. However, if you could find the location of the parent process's PSP, you'd be able to use the same technique to examine its environment block as well.
If you look in a program's PSP, you can find a pointer to the PSP of its parent process (COMMAND.COM if you run a program from a DOS command line). An unsigned integer that's equal to the segment address of the parent process's PSP is at bytes 22 and 23 of the program's PSP.
As was the case with the pointer to the environment block, we'll
need to convert this segment pointer to either a far or a huge
pointer. Since we'll later want to retrieve bytes 44 and
45 of this PSP (and a char is one-byte wide), we can
use the same method we used to convert the environment variable's
segment address. When we're done, we'll have valid
pointers to both the parent process's PSP and its environment
block.
Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.