PRODUCT : Borland C++ NUMBER : 1766 VERSION : 1.01 OS : OS/2 DATE : January 11, 1994 PAGE : 1/3 TITLE : Corrected DosScanEnv() usage example /* DOSSCAN.CPP: Corrected DosScanEnv() usage example This example demonstrates the use of the DosScanEnv() and DosSearchPath() API functions. It scans the environment segment for the PATH variable, and prints its value. It then searches the path given by insert- ing the current directory into the value of the PATH variable for the file named 'cmd.exe', and prints the full file name. NOTES: (1) The OS/2 2.0 and 2.1 online example for the DosScanEnv() function is in error. Please see NOTE above the DosScanEnv() call for details. (2) Error handling is not intended to be an example of proper technique but is intended only to supply all information in this regard that is pertinent. (3) Do not compile this example as a PM EXE! Doing so will inhibit the creation of an OS/2 window and output. */ #include #define INCL_DOS #define INCL_DOSERRORS #include #define ENVVARNAME "PATH" // Environment variable name #define FILENAME "CMD.EXE" // File for which to search //************************************************************** int main(void) { PSZ ResultPointer; // Environment scan result // pointer (returned) BYTE ResultBuffer[128]; // Path search result (returned) APIRET rc; // Return code // Scan environment segment for PATH; notice the far-string // pointer specification ("%Fs") used to print. // NOTE: In the corrected example we take the address of the // ResultPointer in the call to DosScanEnv(); the IBM // online example is erroneous in this regard PRODUCT : Borland C++ NUMBER : 1766 VERSION : 1.01 OS : OS/2 DATE : January 11, 1994 PAGE : 2/3 TITLE : Corrected DosScanEnv() usage example // Environment variable name // | Scan result pointer // | | (returned) // V V if ((rc=DosScanEnv(ENVVARNAME, &ResultPointer)) == NO_ERROR) { printf("%s is %Fs\n", ENVVARNAME, ResultPointer); } else { printf("DosScanEnv() - "); switch(rc) { case ERROR_ENVVAR_NOT_FOUND: // (203) printf("ERROR_ENVVAR_NOT_FOUND\n"); break; default: printf("undocumented error %d\n", rc); break; } return 1; } // Search the ASCIIZ string in 'ResultPointer' returned by // the DosScanEnv() call for "CMD.EXE" if ((rc=DosSearchPath(0L, ResultPointer, FILENAME, ResultBuffer, sizeof(ResultBuffer))) == NO_ERROR) { printf("Found desired file -- %s\n", ResultBuffer); } else { printf("DosSearchPath() - "); switch(rc) { case ERROR_INVALID_FUNCTION: // (1) printf("ERROR_INVALID_FUNCTION\n"); break; case ERROR_FILE_NOT_FOUND: // (2) printf("ERROR_FILE_NOT_FOUND\n"); break; case ERROR_INVALID_PARAMETER: // (87) printf("ERROR_INVALID_PARAMETER \n"); break; case ERROR_BUFFER_OVERFLOW: // (111) printf("ERROR_BUFFER_OVERFLOW\n"); break; case ERROR_ENVVAR_NOT_FOUND: // (203) PRODUCT : Borland C++ NUMBER : 1766 VERSION : 1.01 OS : OS/2 DATE : January 11, 1994 PAGE : 3/3 TITLE : Corrected DosScanEnv() usage example printf("ERROR_ENVAR_NOT_FOUND\n"); break; default: printf("undocumented error %d\n", rc); break; } return 1; } return 0; } // end of main() DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.