source: trunk/src/helpers/apps.c@ 187

Last change on this file since 187 was 185, checked in by umoeller, 23 years ago

Third round of fixes for 0.9.19 (BAT files)

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 69.9 KB
Line 
1
2/*
3 *@@sourcefile apps.c:
4 * contains program helpers (environments, application start).
5 *
6 * This file is new with V0.9.12 and contains functions
7 * previously in winh.c and dosh2.c.
8 *
9 * Note: Version numbering in this file relates to XWorkplace version
10 * numbering.
11 *
12 *@@header "helpers\apps.h"
13 *@@added V0.9.12 (2001-05-26) [umoeller]
14 */
15
16/*
17 * Copyright (C) 1997-2001 Ulrich M”ller.
18 * This file is part of the "XWorkplace helpers" source package.
19 * This is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published
21 * by the Free Software Foundation, in version 2 as it comes in the
22 * "COPYING" file of the XWorkplace main distribution.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 */
28
29#define OS2EMX_PLAIN_CHAR
30 // this is needed for "os2emx.h"; if this is defined,
31 // emx will define PSZ as _signed_ char, otherwise
32 // as unsigned char
33
34#define INCL_DOSPROCESS
35#define INCL_DOSEXCEPTIONS
36#define INCL_DOSMODULEMGR
37#define INCL_DOSSESMGR
38#define INCL_DOSERRORS
39
40#define INCL_WINPROGRAMLIST // needed for PROGDETAILS, wppgm.h
41#define INCL_WINERRORS
42#define INCL_SHLERRORS
43#include <os2.h>
44
45#include <stdio.h>
46#include <setjmp.h> // needed for except.h
47#include <assert.h> // needed for except.h
48
49#include "setup.h" // code generation and debugging options
50
51#include "helpers\dosh.h"
52#include "helpers\except.h" // exception handling
53#include "helpers\prfh.h"
54#include "helpers\standards.h" // some standard macros
55#include "helpers\stringh.h"
56#include "helpers\winh.h"
57#include "helpers\xstring.h"
58
59#include "helpers\apps.h"
60
61/*
62 *@@category: Helpers\PM helpers\Application helpers
63 */
64
65/* ******************************************************************
66 *
67 * Environment helpers
68 *
69 ********************************************************************/
70
71/*
72 *@@ appQueryEnvironmentLen:
73 * returns the total length of the passed in environment
74 * string buffer, including the terminating two null bytes.
75 *
76 *@@added V0.9.16 (2002-01-09) [umoeller]
77 */
78
79ULONG appQueryEnvironmentLen(PCSZ pcszEnvironment)
80{
81 ULONG cbEnvironment = 0;
82 if (pcszEnvironment)
83 {
84 PCSZ pVarThis = pcszEnvironment;
85 // go thru the environment strings; last one has two null bytes
86 while (*pVarThis)
87 {
88 ULONG ulLenThis = strlen(pVarThis) + 1;
89 cbEnvironment += ulLenThis;
90 pVarThis += ulLenThis;
91 }
92
93 cbEnvironment++; // last null byte
94 }
95
96 return cbEnvironment;
97}
98
99/*
100 *@@ appParseEnvironment:
101 * this takes one of those ugly environment strings
102 * as used by DosStartSession and WinStartApp (with
103 * lots of zero-terminated strings one after another
104 * and a duplicate zero byte as a terminator) as
105 * input and splits it into an array of separate
106 * strings in pEnv.
107 *
108 * The newly allocated strings are stored in in
109 * pEnv->papszVars. The array count is stored in
110 * pEnv->cVars.
111 *
112 * Each environment variable will be copied into
113 * one newly allocated string in the array. Use
114 * appFreeEnvironment to free the memory allocated
115 * by this function.
116 *
117 * Use the following code to browse thru the array:
118 +
119 + DOSENVIRONMENT Env = {0};
120 + if (appParseEnvironment(pszEnv,
121 + &Env)
122 + == NO_ERROR)
123 + {
124 + if (Env.papszVars)
125 + {
126 + PSZ *ppszThis = Env.papszVars;
127 + for (ul = 0;
128 + ul < Env.cVars;
129 + ul++)
130 + {
131 + PSZ pszThis = *ppszThis;
132 + // pszThis now has something like PATH=C:\TEMP
133 + // ...
134 + // next environment string
135 + ppszThis++;
136 + }
137 + }
138 + appFreeEnvironment(&Env);
139 + }
140 *
141 *@@added V0.9.4 (2000-08-02) [umoeller]
142 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
143 */
144
145APIRET appParseEnvironment(const char *pcszEnv,
146 PDOSENVIRONMENT pEnv) // out: new environment
147{
148 APIRET arc = NO_ERROR;
149 if (!pcszEnv)
150 arc = ERROR_INVALID_PARAMETER;
151 else
152 {
153 PSZ pszVarThis = (PSZ)pcszEnv;
154 ULONG cVars = 0;
155 // count strings
156 while (*pszVarThis)
157 {
158 cVars++;
159 pszVarThis += strlen(pszVarThis) + 1;
160 }
161
162 pEnv->cVars = 0;
163 pEnv->papszVars = 0;
164
165 if (cVars)
166 {
167 ULONG cbArray = sizeof(PSZ) * cVars;
168 PSZ *papsz;
169 if (!(papsz = (PSZ*)malloc(cbArray)))
170 arc = ERROR_NOT_ENOUGH_MEMORY;
171 else
172 {
173 PSZ *ppszTarget = papsz;
174 memset(papsz, 0, cbArray);
175 pszVarThis = (PSZ)pcszEnv;
176 while (*pszVarThis)
177 {
178 ULONG ulThisLen;
179 if (!(*ppszTarget = strhdup(pszVarThis, &ulThisLen)))
180 {
181 arc = ERROR_NOT_ENOUGH_MEMORY;
182 break;
183 }
184 (pEnv->cVars)++;
185 ppszTarget++;
186 pszVarThis += ulThisLen + 1;
187 }
188
189 pEnv->papszVars = papsz;
190 }
191 }
192 }
193
194 return arc;
195}
196
197/*
198 *@@ appGetEnvironment:
199 * calls appParseEnvironment for the current
200 * process environment, which is retrieved from
201 * the info blocks.
202 *
203 * Returns:
204 *
205 * -- NO_ERROR:
206 *
207 * -- ERROR_INVALID_PARAMETER
208 *
209 * -- ERROR_BAD_ENVIRONMENT: no environment found in
210 * info blocks.
211 *
212 *@@added V0.9.4 (2000-07-19) [umoeller]
213 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
214 */
215
216APIRET appGetEnvironment(PDOSENVIRONMENT pEnv)
217{
218 APIRET arc = NO_ERROR;
219 if (!pEnv)
220 arc = ERROR_INVALID_PARAMETER;
221 else
222 {
223 PTIB ptib = 0;
224 PPIB ppib = 0;
225 arc = DosGetInfoBlocks(&ptib, &ppib);
226 if (arc == NO_ERROR)
227 {
228 PSZ pszEnv;
229 if (pszEnv = ppib->pib_pchenv)
230 arc = appParseEnvironment(pszEnv, pEnv);
231 else
232 arc = ERROR_BAD_ENVIRONMENT;
233 }
234 }
235
236 return arc;
237}
238
239/*
240 *@@ appFindEnvironmentVar:
241 * returns the PSZ* in the pEnv->papszVars array
242 * which specifies the environment variable in pszVarName.
243 *
244 * With pszVarName, you can either specify the variable
245 * name only ("VARNAME") or a full environment string
246 * ("VARNAME=BLAH"). In any case, only the variable name
247 * is compared.
248 *
249 * Returns NULL if no such variable name was found in
250 * the array.
251 *
252 *@@added V0.9.4 (2000-07-19) [umoeller]
253 *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
254 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
255 *@@changed V0.9.16 (2002-01-01) [umoeller]: removed extra heap allocation
256 */
257
258PSZ* appFindEnvironmentVar(PDOSENVIRONMENT pEnv,
259 PSZ pszVarName)
260{
261 PSZ *ppszRet = 0;
262
263 if ( (pEnv)
264 && (pEnv->papszVars)
265 && (pszVarName)
266 )
267 {
268 ULONG ul = 0;
269 ULONG ulVarNameLen = 0;
270
271 PSZ pFirstEqual;
272 // rewrote all the following for speed V0.9.16 (2002-01-01) [umoeller]
273 if (pFirstEqual = strchr(pszVarName, '='))
274 // VAR=VALUE
275 // ^ pFirstEqual
276 ulVarNameLen = pFirstEqual - pszVarName;
277 else
278 ulVarNameLen = strlen(pszVarName);
279
280 for (ul = 0;
281 ul < pEnv->cVars;
282 ul++)
283 {
284 PSZ pszThis = pEnv->papszVars[ul];
285 if (pFirstEqual = strchr(pszThis, '='))
286 {
287 ULONG ulLenThis = pFirstEqual - pszThis;
288 if ( (ulLenThis == ulVarNameLen)
289 && (!memicmp(pszThis,
290 pszVarName,
291 ulVarNameLen))
292 )
293 {
294 ppszRet = &pEnv->papszVars[ul];
295 break;
296 }
297 }
298 }
299 }
300
301 return ppszRet;
302}
303
304/*
305 *@@ appSetEnvironmentVar:
306 * sets an environment variable in the specified
307 * environment, which must have been initialized
308 * using appGetEnvironment first.
309 *
310 * pszNewEnv must be a full environment string
311 * in the form "VARNAME=VALUE".
312 *
313 * If "VARNAME" has already been set to something
314 * in the string array in pEnv, that array item
315 * is replaced.
316 *
317 * OTOH, if "VARNAME" has not been set yet, a new
318 * item is added to the array, and pEnv->cVars is
319 * raised by one. In that case, fAddFirst determines
320 * whether the new array item is added to the front
321 * or the tail of the environment list.
322 *
323 *@@added V0.9.4 (2000-07-19) [umoeller]
324 *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst
325 *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
326 *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed crash if !fAddFirst
327 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
328 */
329
330APIRET appSetEnvironmentVar(PDOSENVIRONMENT pEnv,
331 PSZ pszNewEnv,
332 BOOL fAddFirst)
333{
334 APIRET arc = NO_ERROR;
335 if ((!pEnv) || (!pszNewEnv))
336 arc = ERROR_INVALID_PARAMETER;
337 else
338 {
339 if (!pEnv->papszVars)
340 {
341 // no variables set yet:
342 pEnv->papszVars = (PSZ*)malloc(sizeof(PSZ));
343 pEnv->cVars = 1;
344
345 *(pEnv->papszVars) = strdup(pszNewEnv);
346 }
347 else
348 {
349 PSZ *ppszEnvLine;
350 if (ppszEnvLine = appFindEnvironmentVar(pEnv, pszNewEnv))
351 // was set already: replace
352 arc = strhStore(ppszEnvLine,
353 pszNewEnv,
354 NULL);
355 else
356 {
357 // not set already:
358 PSZ *ppszNew = NULL;
359
360 // allocate new array, with one new entry
361 // fixed V0.9.12 (2001-05-26) [umoeller], this crashed
362 PSZ *papszNew;
363
364 if (!(papszNew = (PSZ*)malloc(sizeof(PSZ) * (pEnv->cVars + 1))))
365 arc = ERROR_NOT_ENOUGH_MEMORY;
366 else
367 {
368 if (fAddFirst)
369 {
370 // add as first entry:
371 // overwrite first entry
372 ppszNew = papszNew;
373 // copy old entries
374 memcpy(papszNew + 1, // second new entry
375 pEnv->papszVars, // first old entry
376 sizeof(PSZ) * pEnv->cVars);
377 }
378 else
379 {
380 // append at the tail:
381 // overwrite last entry
382 ppszNew = papszNew + pEnv->cVars;
383 // copy old entries
384 memcpy(papszNew, // first new entry
385 pEnv->papszVars, // first old entry
386 sizeof(PSZ) * pEnv->cVars);
387 }
388
389 free(pEnv->papszVars); // was missing V0.9.12 (2001-05-21) [umoeller]
390 pEnv->papszVars = papszNew;
391 pEnv->cVars++;
392 *ppszNew = strdup(pszNewEnv);
393 }
394 }
395 }
396 }
397
398 return arc;
399}
400
401/*
402 *@@ appConvertEnvironment:
403 * converts an environment initialized by appGetEnvironment
404 * to the string format required by WinStartApp and DosExecPgm,
405 * that is, one memory block is allocated in *ppszEnv and all
406 * strings in pEnv->papszVars are copied to that block. Each
407 * string is terminated with a null character; the last string
408 * is terminated with two null characters.
409 *
410 * Use free() to free the memory block allocated by this
411 * function in *ppszEnv.
412 *
413 *@@added V0.9.4 (2000-07-19) [umoeller]
414 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
415 */
416
417APIRET appConvertEnvironment(PDOSENVIRONMENT pEnv,
418 PSZ *ppszEnv, // out: environment string
419 PULONG pulSize) // out: size of block allocated in *ppszEnv; ptr can be NULL
420{
421 APIRET arc = NO_ERROR;
422 if ( (!pEnv)
423 || (!pEnv->papszVars)
424 )
425 arc = ERROR_INVALID_PARAMETER;
426 else
427 {
428 // count memory needed for all strings
429 ULONG cbNeeded = 0,
430 ul = 0;
431 PSZ *ppszThis = pEnv->papszVars;
432
433 for (ul = 0;
434 ul < pEnv->cVars;
435 ul++)
436 {
437 cbNeeded += strlen(*ppszThis) + 1; // length of string plus null terminator
438
439 // next environment string
440 ppszThis++;
441 }
442
443 cbNeeded++; // for another null terminator
444
445 if (!(*ppszEnv = (PSZ)malloc(cbNeeded)))
446 arc = ERROR_NOT_ENOUGH_MEMORY;
447 else
448 {
449 PSZ pTarget = *ppszEnv;
450 if (pulSize)
451 *pulSize = cbNeeded;
452 ppszThis = pEnv->papszVars;
453
454 // now copy each string
455 for (ul = 0;
456 ul < pEnv->cVars;
457 ul++)
458 {
459 PSZ pSource = *ppszThis;
460
461 while ((*pTarget++ = *pSource++))
462 ;
463
464 // *pTarget++ = 0; // append null terminator per string
465
466 // next environment string
467 ppszThis++;
468 }
469
470 *pTarget++ = 0; // append second null terminator
471 }
472 }
473
474 return arc;
475}
476
477/*
478 *@@ appFreeEnvironment:
479 * frees memory allocated by appGetEnvironment.
480 *
481 *@@added V0.9.4 (2000-07-19) [umoeller]
482 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
483 */
484
485APIRET appFreeEnvironment(PDOSENVIRONMENT pEnv)
486{
487 APIRET arc = NO_ERROR;
488 if ( (!pEnv)
489 || (!pEnv->papszVars)
490 )
491 arc = ERROR_INVALID_PARAMETER;
492 else
493 {
494 PSZ *ppszThis = pEnv->papszVars;
495 PSZ pszThis;
496 ULONG ul = 0;
497
498 for (ul = 0;
499 ul < pEnv->cVars;
500 ul++)
501 {
502 pszThis = *ppszThis;
503 free(pszThis);
504 // *ppszThis = NULL;
505 // next environment string
506 ppszThis++;
507 }
508
509 free(pEnv->papszVars);
510 pEnv->cVars = 0;
511 }
512
513 return arc;
514}
515
516/* ******************************************************************
517 *
518 * Application information
519 *
520 ********************************************************************/
521
522/*
523 *@@ appQueryAppType:
524 * returns the Control Program (Dos) and
525 * Win* PROG_* application types for the
526 * specified executable. Essentially, this
527 * is a wrapper around DosQueryAppType.
528 *
529 * pcszExecutable must be fully qualified.
530 * You can use doshFindExecutable to qualify
531 * it.
532 *
533 * This returns the APIRET of DosQueryAppType.
534 * If this is NO_ERROR; *pulDosAppType receives
535 * the app type of DosQueryAppType. In addition,
536 * *pulWinAppType is set to one of the following:
537 *
538 * -- PROG_FULLSCREEN
539 *
540 * -- PROG_PDD
541 *
542 * -- PROG_VDD
543 *
544 * -- PROG_DLL
545 *
546 * -- PROG_WINDOWEDVDM
547 *
548 * -- PROG_PM
549 *
550 * -- PROG_31_ENHSEAMLESSCOMMON
551 *
552 * -- PROG_WINDOWABLEVIO
553 *
554 * -- PROG_DEFAULT
555 *
556 *@@added V0.9.9 (2001-03-07) [umoeller]
557 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
558 *@@changed V0.9.14 (2001-08-07) [pr]: use FAPPTYP_* constants
559 *@@changed V0.9.16 (2001-12-08) [umoeller]: added checks for batch files, other optimizations
560 */
561
562APIRET appQueryAppType(const char *pcszExecutable,
563 PULONG pulDosAppType, // out: DOS app type
564 PULONG pulWinAppType) // out: PROG_* app type
565{
566 APIRET arc;
567
568/*
569 #define FAPPTYP_NOTSPEC 0x0000
570 #define FAPPTYP_NOTWINDOWCOMPAT 0x0001
571 #define FAPPTYP_WINDOWCOMPAT 0x0002
572 #define FAPPTYP_WINDOWAPI 0x0003
573 #define FAPPTYP_BOUND 0x0008
574 #define FAPPTYP_DLL 0x0010
575 #define FAPPTYP_DOS 0x0020
576 #define FAPPTYP_PHYSDRV 0x0040 // physical device driver
577 #define FAPPTYP_VIRTDRV 0x0080 // virtual device driver
578 #define FAPPTYP_PROTDLL 0x0100 // 'protected memory' dll
579 #define FAPPTYP_WINDOWSREAL 0x0200 // Windows real mode app
580 #define FAPPTYP_WINDOWSPROT 0x0400 // Windows protect mode app
581 #define FAPPTYP_WINDOWSPROT31 0x1000 // Windows 3.1 protect mode app
582 #define FAPPTYP_32BIT 0x4000
583*/
584
585 ULONG ulWinAppType = PROG_DEFAULT;
586
587 if (!(arc = DosQueryAppType((PSZ)pcszExecutable, pulDosAppType)))
588 {
589 // clear the 32-bit flag
590 // V0.9.16 (2001-12-08) [umoeller]
591 ULONG ulDosAppType = (*pulDosAppType) & ~FAPPTYP_32BIT,
592 ulLoAppType = ulDosAppType & 0xFFFF;
593
594 if (ulDosAppType & FAPPTYP_PHYSDRV) // 0x40
595 ulWinAppType = PROG_PDD;
596 else if (ulDosAppType & FAPPTYP_VIRTDRV) // 0x80
597 ulWinAppType = PROG_VDD;
598 else if ((ulDosAppType & 0xF0) == FAPPTYP_DLL) // 0x10
599 // DLL bit set
600 ulWinAppType = PROG_DLL;
601 else if (ulDosAppType & FAPPTYP_DOS) // 0x20
602 // DOS bit set?
603 ulWinAppType = PROG_WINDOWEDVDM;
604 else if ((ulDosAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) // 0x0003)
605 // "Window-API" == PM
606 ulWinAppType = PROG_PM;
607 else if (ulLoAppType == FAPPTYP_WINDOWSREAL)
608 ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // @@todo really?
609 else if ( (ulLoAppType == FAPPTYP_WINDOWSPROT31) // 0x1000) // windows program (?!?)
610 || (ulLoAppType == FAPPTYP_WINDOWSPROT) // ) // windows program (?!?)
611 )
612 ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // PROG_31_ENH;
613 else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_WINDOWCOMPAT) // 0x02)
614 ulWinAppType = PROG_WINDOWABLEVIO;
615 else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_NOTWINDOWCOMPAT) // 0x01)
616 ulWinAppType = PROG_FULLSCREEN;
617 }
618
619 if (ulWinAppType == PROG_DEFAULT)
620 {
621 // added checks for batch files V0.9.16 (2001-12-08) [umoeller]
622 PCSZ pcszExt;
623 if (pcszExt = doshGetExtension(pcszExecutable))
624 {
625 if (!stricmp(pcszExt, "BAT"))
626 {
627 ulWinAppType = PROG_WINDOWEDVDM;
628 arc = NO_ERROR;
629 }
630 else if (!stricmp(pcszExt, "CMD"))
631 {
632 ulWinAppType = PROG_WINDOWABLEVIO;
633 arc = NO_ERROR;
634 }
635 }
636 }
637
638 *pulWinAppType = ulWinAppType;
639
640 return arc;
641}
642
643/*
644 *@@ PROGTYPESTRING:
645 *
646 *@@added V0.9.16 (2002-01-13) [umoeller]
647 */
648
649typedef struct _PROGTYPESTRING
650{
651 PROGCATEGORY progc;
652 PCSZ pcsz;
653} PROGTYPESTRING, *PPROGTYPESTRING;
654
655PROGTYPESTRING G_aProgTypes[] =
656 {
657 PROG_DEFAULT, "PROG_DEFAULT",
658 PROG_FULLSCREEN, "PROG_FULLSCREEN",
659 PROG_WINDOWABLEVIO, "PROG_WINDOWABLEVIO",
660 PROG_PM, "PROG_PM",
661 PROG_GROUP, "PROG_GROUP",
662 PROG_VDM, "PROG_VDM",
663 // same as PROG_REAL, "PROG_REAL",
664 PROG_WINDOWEDVDM, "PROG_WINDOWEDVDM",
665 PROG_DLL, "PROG_DLL",
666 PROG_PDD, "PROG_PDD",
667 PROG_VDD, "PROG_VDD",
668 PROG_WINDOW_REAL, "PROG_WINDOW_REAL",
669 PROG_30_STD, "PROG_30_STD",
670 // same as PROG_WINDOW_PROT, "PROG_WINDOW_PROT",
671 PROG_WINDOW_AUTO, "PROG_WINDOW_AUTO",
672 PROG_30_STDSEAMLESSVDM, "PROG_30_STDSEAMLESSVDM",
673 // same as PROG_SEAMLESSVDM, "PROG_SEAMLESSVDM",
674 PROG_30_STDSEAMLESSCOMMON, "PROG_30_STDSEAMLESSCOMMON",
675 // same as PROG_SEAMLESSCOMMON, "PROG_SEAMLESSCOMMON",
676 PROG_31_STDSEAMLESSVDM, "PROG_31_STDSEAMLESSVDM",
677 PROG_31_STDSEAMLESSCOMMON, "PROG_31_STDSEAMLESSCOMMON",
678 PROG_31_ENHSEAMLESSVDM, "PROG_31_ENHSEAMLESSVDM",
679 PROG_31_ENHSEAMLESSCOMMON, "PROG_31_ENHSEAMLESSCOMMON",
680 PROG_31_ENH, "PROG_31_ENH",
681 PROG_31_STD, "PROG_31_STD",
682
683// Warp 4 toolkit defines, whatever these were designed for...
684#ifndef PROG_DOS_GAME
685 #define PROG_DOS_GAME (PROGCATEGORY)21
686#endif
687#ifndef PROG_WIN_GAME
688 #define PROG_WIN_GAME (PROGCATEGORY)22
689#endif
690#ifndef PROG_DOS_MODE
691 #define PROG_DOS_MODE (PROGCATEGORY)23
692#endif
693
694 PROG_DOS_GAME, "PROG_DOS_GAME",
695 PROG_WIN_GAME, "PROG_WIN_GAME",
696 PROG_DOS_MODE, "PROG_DOS_MODE",
697
698 // added this V0.9.16 (2001-12-08) [umoeller]
699 PROG_WIN32, "PROG_WIN32"
700 };
701
702/*
703 *@@ appDescribeAppType:
704 * returns a "PROG_*" string for the given
705 * program type. Useful for WPProgram setup
706 * strings and such.
707 *
708 *@@added V0.9.16 (2001-10-06)
709 */
710
711PCSZ appDescribeAppType(PROGCATEGORY progc) // in: from PROGDETAILS.progc
712{
713 ULONG ul;
714 for (ul = 0;
715 ul < ARRAYITEMCOUNT(G_aProgTypes);
716 ul++)
717 {
718 if (G_aProgTypes[ul].progc == progc)
719 return G_aProgTypes[ul].pcsz;
720 }
721
722 return NULL;
723}
724
725/*
726 *@@ appIsWindowsApp:
727 * checks the specified program category
728 * (PROGDETAILS.progt.progc) for whether
729 * it represents a Win-OS/2 application.
730 *
731 * Returns:
732 *
733 * -- 0: no windows app (it's VIO, OS/2
734 * or DOS fullscreen, or PM).
735 *
736 * -- 1: Win-OS/2 standard app.
737 *
738 * -- 2: Win-OS/2 enhanced-mode app.
739 *
740 *@@added V0.9.12 (2001-05-26) [umoeller]
741 */
742
743ULONG appIsWindowsApp(ULONG ulProgCategory)
744{
745 switch (ulProgCategory)
746 {
747 case PROG_31_ENHSEAMLESSVDM: // 17
748 case PROG_31_ENHSEAMLESSCOMMON: // 18
749 case PROG_31_ENH: // 19
750 return 2;
751
752#ifndef PROG_30_STD
753 #define PROG_30_STD (PROGCATEGORY)11
754#endif
755
756#ifndef PROG_30_STDSEAMLESSVDM
757 #define PROG_30_STDSEAMLESSVDM (PROGCATEGORY)13
758#endif
759
760 case PROG_WINDOW_REAL: // 10
761 case PROG_30_STD: // 11
762 case PROG_WINDOW_AUTO: // 12
763 case PROG_30_STDSEAMLESSVDM: // 13
764 case PROG_30_STDSEAMLESSCOMMON: // 14
765 case PROG_31_STDSEAMLESSVDM: // 15
766 case PROG_31_STDSEAMLESSCOMMON: // 16
767 case PROG_31_STD: // 20
768 return 1;
769 }
770
771 return 0;
772}
773
774/* ******************************************************************
775 *
776 * Application start
777 *
778 ********************************************************************/
779
780/*
781 *@@ CheckAndQualifyExecutable:
782 * checks the executable in the given PROGDETAILS
783 * for whether it is fully qualified.
784 *
785 * If so, the existence is verified.
786 *
787 * If not, we search for it on the PATH. If we
788 * find it, we use pstrExecutablePath to store
789 * the fully qualified executable and set
790 * pDetails->pszExecutable to it. The caller
791 * must initialize the buffer and clear it
792 * after the call.
793 *
794 * Returns:
795 *
796 * -- NO_ERROR: executable exists and might
797 * have been fully qualified.
798 *
799 * -- ERROR_FILE_NOT_FOUND
800 *
801 *@@added V0.9.20 (2002-07-03) [umoeller]
802 */
803
804static APIRET CheckAndQualifyExecutable(PPROGDETAILS pDetails, // in/out: program details
805 PXSTRING pstrExecutablePatched) // in/out: buffer for q'fied exec (must be init'ed)
806{
807 APIRET arc = NO_ERROR;
808
809 ULONG ulAttr;
810 // check if the executable is fully qualified; if so,
811 // check if the executable file exists
812 if ( (pDetails->pszExecutable[1] == ':')
813 && (strchr(pDetails->pszExecutable, '\\'))
814 )
815 {
816 arc = doshQueryPathAttr(pDetails->pszExecutable,
817 &ulAttr);
818 }
819 else
820 {
821 // _not_ fully qualified: look it up on the PATH then
822 // V0.9.16 (2001-12-06) [umoeller]
823 CHAR szFQExecutable[CCHMAXPATH];
824 if (!(arc = doshSearchPath("PATH",
825 pDetails->pszExecutable,
826 szFQExecutable,
827 sizeof(szFQExecutable))))
828 {
829 // alright, found it:
830 xstrcpy(pstrExecutablePatched, szFQExecutable, 0);
831 pDetails->pszExecutable = pstrExecutablePatched->psz;
832 }
833 }
834
835 return arc;
836}
837
838/*
839 *@@ CallBatchCorrectly:
840 * fixes the specified PROGDETAILS for
841 * command files in the executable part
842 * by inserting /C XXX into the parameters
843 * and setting the executable to the fully
844 * qualified command interpreter specified
845 * by the given environment variable.
846 *
847 *@@added V0.9.6 (2000-10-16) [umoeller]
848 *@@changed V0.9.7 (2001-01-15) [umoeller]: now using XSTRING
849 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
850 *@@changed V0.9.20 (2002-07-03) [umoeller]: now always qualifying executable to fix broken BAT files
851 */
852
853static APIRET CallBatchCorrectly(PPROGDETAILS pProgDetails,
854 PXSTRING pstrExecutablePatched, // in/out: buffer for q'fied exec (must be init'ed)
855 PXSTRING pstrParams, // in/out: modified parameters (reallocated)
856 const char *pcszEnvVar, // in: env var spec'g command proc
857 // (e.g. "OS2_SHELL"); can be NULL
858 const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE")
859{
860 APIRET arc = NO_ERROR;
861
862 // XXX.CMD file as executable:
863 // fix args to /C XXX.CMD
864
865 PSZ pszOldParams = NULL;
866 ULONG ulOldParamsLength = pstrParams->ulLength;
867 if (ulOldParamsLength)
868 // we have parameters already:
869 // make a backup... we'll append that later
870 pszOldParams = strdup(pstrParams->psz);
871
872 // set new params to "/C filename.cmd"
873 xstrcpy(pstrParams, "/C ", 0);
874 xstrcat(pstrParams,
875 pProgDetails->pszExecutable,
876 0);
877
878 if (pszOldParams)
879 {
880 // .cmd had params:
881 // append space and old params
882 xstrcatc(pstrParams, ' ');
883 xstrcat(pstrParams,
884 pszOldParams,
885 ulOldParamsLength);
886 free(pszOldParams);
887 }
888
889 // set executable to $(OS2_SHELL)
890 pProgDetails->pszExecutable = NULL;
891 if (pcszEnvVar)
892 pProgDetails->pszExecutable = getenv(pcszEnvVar);
893 if (!pProgDetails->pszExecutable)
894 pProgDetails->pszExecutable = (PSZ)pcszDefProc;
895 // should be on PATH
896
897 // and make sure this is always qualified
898 // V0.9.20 (2002-07-03) [umoeller]
899 return CheckAndQualifyExecutable(pProgDetails,
900 pstrExecutablePatched);
901}
902
903/*
904 *@@ appQueryDefaultWin31Environment:
905 * returns the default Win-OS/2 3.1 environment
906 * from OS2.INI, which you can then merge with
907 * your process environment to be able to
908 * start Win-OS/2 sessions properly with
909 * appStartApp.
910 *
911 * Caller must free() the return value.
912 *
913 *@@added V0.9.12 (2001-05-26) [umoeller]
914 *@@changed V0.9.19 (2002-03-28) [umoeller]: now returning APIRET
915 */
916
917APIRET appQueryDefaultWin31Environment(PSZ *ppsz)
918{
919 APIRET arc = NO_ERROR;
920 PSZ pszReturn = NULL;
921 ULONG ulSize = 0;
922
923 // get default environment (from Win-OS/2 settings object) from OS2.INI
924 PSZ pszDefEnv;
925 if (pszDefEnv = prfhQueryProfileData(HINI_USER,
926 "WINOS2",
927 "PM_GlobalWindows31Settings",
928 &ulSize))
929 {
930 if (pszReturn = (PSZ)malloc(ulSize + 2))
931 {
932 PSZ p;
933 memset(pszReturn, 0, ulSize + 2);
934 memcpy(pszReturn, pszDefEnv, ulSize);
935
936 for (p = pszReturn;
937 p < pszReturn + ulSize;
938 p++)
939 if (*p == ';')
940 *p = 0;
941
942 // okay.... now we got an OS/2-style environment
943 // with 0, 0, 00 strings
944
945 *ppsz = pszReturn;
946 }
947 else
948 arc = ERROR_NOT_ENOUGH_MEMORY;
949
950 free(pszDefEnv);
951 }
952 else
953 arc = ERROR_BAD_ENVIRONMENT;
954
955 return arc;
956}
957
958#ifdef _PMPRINTF_
959
960static void DumpMemoryBlock(PBYTE pb, // in: start address
961 ULONG ulSize, // in: size of block
962 ULONG ulIndent) // in: how many spaces to put
963 // before each output line
964{
965 TRY_QUIET(excpt1)
966 {
967 PBYTE pbCurrent = pb; // current byte
968 ULONG ulCount = 0,
969 ulCharsInLine = 0; // if this grows > 7, a new line is started
970 CHAR szTemp[1000];
971 CHAR szLine[400] = "",
972 szAscii[30] = " "; // ASCII representation; filled for every line
973 PSZ pszLine = szLine,
974 pszAscii = szAscii;
975
976 for (pbCurrent = pb;
977 ulCount < ulSize;
978 pbCurrent++, ulCount++)
979 {
980 if (ulCharsInLine == 0)
981 {
982 memset(szLine, ' ', ulIndent);
983 pszLine += ulIndent;
984 }
985 pszLine += sprintf(pszLine, "%02lX ", (ULONG)*pbCurrent);
986
987 if ( (*pbCurrent > 31) && (*pbCurrent < 127) )
988 // printable character:
989 *pszAscii = *pbCurrent;
990 else
991 *pszAscii = '.';
992 pszAscii++;
993
994 ulCharsInLine++;
995 if ( (ulCharsInLine > 7) // 8 bytes added?
996 || (ulCount == ulSize-1) // end of buffer reached?
997 )
998 {
999 // if we haven't had eight bytes yet,
1000 // fill buffer up to eight bytes with spaces
1001 ULONG ul2;
1002 for (ul2 = ulCharsInLine;
1003 ul2 < 8;
1004 ul2++)
1005 pszLine += sprintf(pszLine, " ");
1006
1007 sprintf(szTemp, "%04lX: %s %ss",
1008 (ulCount & 0xFFFFFFF8), // offset in hex
1009 szLine, // bytes string
1010 szAscii); // ASCII string
1011
1012 _Pmpf(("%s", szTemp));
1013
1014 // restart line buffer
1015 pszLine = szLine;
1016
1017 // clear ASCII buffer
1018 strcpy(szAscii, " ");
1019 pszAscii = szAscii;
1020
1021 // reset line counter
1022 ulCharsInLine = 0;
1023 }
1024 }
1025
1026 }
1027 CATCH(excpt1)
1028 {
1029 _Pmpf(("Crash in " __FUNCTION__ ));
1030 } END_CATCH();
1031}
1032
1033#endif
1034
1035/*
1036 *@@ appBuildProgDetails:
1037 * extracted code from appStartApp to fix the
1038 * given PROGDETAILS data to support the typical
1039 * WPS stuff and allocate a single block of
1040 * shared memory containing all the data.
1041 *
1042 * This is now used by XWP's progOpenProgram
1043 * directly as a temporary fix for all the
1044 * session hangs.
1045 *
1046 * As input, this takes a PROGDETAILS structure,
1047 * which is converted in various ways. In detail,
1048 * this supports:
1049 *
1050 * -- starting "*" executables (command prompts
1051 * for OS/2, DOS, Win-OS/2);
1052 *
1053 * -- starting ".CMD" and ".BAT" files as
1054 * PROGDETAILS.pszExecutable; for those, we
1055 * convert the executable and parameters to
1056 * start CMD.EXE or COMMAND.COM with the "/C"
1057 * parameter instead;
1058 *
1059 * -- starting apps which are not fully qualified
1060 * and therefore assumed to be on the PATH
1061 * (for which doshSearchPath("PATH") is called).
1062 *
1063 * Unless it is "*", PROGDETAILS.pszExecutable must
1064 * be a proper file name. The full path may be omitted
1065 * if it is on the PATH, but the extension (.EXE etc.)
1066 * must be given. You can use doshFindExecutable to
1067 * find executables if you don't know the extension.
1068 *
1069 * This also handles and merges special and default
1070 * environments for the app to be started. The
1071 * following should be respected:
1072 *
1073 * -- As with WinStartApp, if PROGDETAILS.pszEnvironment
1074 * is NULL, the new app inherits the default environment
1075 * from the shell.
1076 *
1077 * -- However, if you specify an environment, you _must_
1078 * specify a complete environment. This function
1079 * will not merge environments. Use
1080 * appSetEnvironmentVar to change environment
1081 * variables in a complete environment set.
1082 *
1083 * -- If PROGDETAILS specifies a Win-OS/2 session
1084 * and PROGDETAILS.pszEnvironment is empty,
1085 * this uses the default Win-OS/2 environment
1086 * from OS2.INI. See appQueryDefaultWin31Environment.
1087 *
1088 * Even though this isn't clearly said in PMREF,
1089 * PROGDETAILS.swpInitial is important:
1090 *
1091 * -- To start a session minimized, set fl to SWP_MINIMIZE.
1092 *
1093 * -- To start a VIO session with auto-close disabled,
1094 * set the half-documented SWP_NOAUTOCLOSE flag (0x8000)
1095 * This flag is now in the newer toolkit headers.
1096 *
1097 * In addition, this supports the following session
1098 * flags with ulFlags if PROG_DEFAULT is specified:
1099 *
1100 * -- APP_RUN_FULLSCREEN: start a fullscreen session
1101 * for VIO, DOS, and Win-OS/2 programs. Otherwise
1102 * we start a windowed or (share) a seamless session.
1103 * Ignored if the program is PM.
1104 *
1105 * -- APP_RUN_ENHANCED: for Win-OS/2 sessions, use
1106 * enhanced mode.
1107 * Ignored if the program is not Win-OS/2.
1108 *
1109 * -- APP_RUN_STANDARD: for Win-OS/2 sessions, use
1110 * standard mode.
1111 * Ignored if the program is not Win-OS/2.
1112 *
1113 * -- APP_RUN_SEPARATE: for Win-OS/2 sessions, use
1114 * a separate session.
1115 * Ignored if the program is not Win-OS/2.
1116 *
1117 * If NO_ERROR is returned, *ppDetails receives a
1118 * new buffer of shared memory containing all the
1119 * data packed together.
1120 *
1121 * The shared memory is allocated unnamed and
1122 * with OBJ_GETTABLE. It is the responsibility
1123 * of the caller to call DosFreeMem on that buffer.
1124 *
1125 * Returns:
1126 *
1127 * -- NO_ERROR
1128 *
1129 * -- ERROR_INVALID_PARAMETER: pcProgDetails or
1130 * ppDetails is NULL; or PROGDETAILS.pszExecutable is NULL.
1131 *
1132 * -- ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND:
1133 * PROGDETAILS.pszExecutable and/or PROGDETAILS.pszStartupDir
1134 * are invalid.
1135 * A NULL PROGDETAILS.pszStartupDir is supported though.
1136 *
1137 * -- ERROR_BAD_FORMAT
1138 *
1139 * -- ERROR_BAD_ENVIRONMENT: environment is larger than 60.000 bytes.
1140 *
1141 * -- ERROR_NOT_ENOUGH_MEMORY
1142 *
1143 * plus the error codes from doshQueryPathAttr, doshSearchPath,
1144 * appParseEnvironment, appSetEnvironmentVar, and appConvertEnvironment.
1145 *
1146 *@@added V0.9.18 (2002-03-27) [umoeller]
1147 *@@changed V0.9.19 (2002-03-28) [umoeller]: now allocating contiguous buffer
1148 */
1149
1150APIRET appBuildProgDetails(PPROGDETAILS *ppDetails, // out: shared mem with fixed program spec (req.)
1151 const PROGDETAILS *pcProgDetails, // in: program spec (req.)
1152 ULONG ulFlags) // in: APP_RUN_* flags or 0
1153{
1154 APIRET arc = NO_ERROR;
1155
1156 XSTRING strExecutablePatched,
1157 strParamsPatched;
1158 PSZ pszWinOS2Env = 0;
1159
1160 PROGDETAILS Details;
1161
1162 *ppDetails = NULL;
1163
1164 if (!pcProgDetails && !ppDetails)
1165 return (ERROR_INVALID_PARAMETER);
1166
1167 /*
1168 * part 1:
1169 * fix up the PROGDETAILS fields
1170 */
1171
1172 xstrInit(&strExecutablePatched, 0);
1173 xstrInit(&strParamsPatched, 0);
1174
1175 memcpy(&Details, pcProgDetails, sizeof(PROGDETAILS));
1176 // pointers still point into old prog details buffer
1177 Details.Length = sizeof(PROGDETAILS);
1178 Details.progt.fbVisible = SHE_VISIBLE;
1179
1180 // all this only makes sense if this contains something...
1181 // besides, this crashed on string comparisons V0.9.9 (2001-01-27) [umoeller]
1182 if ( (!Details.pszExecutable)
1183 || (!Details.pszExecutable[0])
1184 )
1185 arc = ERROR_INVALID_PARAMETER;
1186 else
1187 {
1188 ULONG ulIsWinApp;
1189
1190 // memset(&Details.swpInitial, 0, sizeof(SWP));
1191 // this wasn't a good idea... WPProgram stores stuff
1192 // in here, such as the "minimize on startup" -> SWP_MINIMIZE
1193
1194 // duplicate parameters...
1195 // we need this for string manipulations below...
1196 if ( (Details.pszParameters)
1197 && (Details.pszParameters[0]) // V0.9.18
1198 )
1199 xstrcpy(&strParamsPatched,
1200 Details.pszParameters,
1201 0);
1202
1203 #ifdef DEBUG_PROGRAMSTART
1204 _PmpfF((" old progc: 0x%lX", pcProgDetails->progt.progc));
1205 _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle)));
1206 _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable)));
1207 _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters)));
1208 _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon)));
1209 #endif
1210
1211 // program type fixups
1212 switch (Details.progt.progc) // that's a ULONG
1213 {
1214 case ((ULONG)-1): // we get that sometimes...
1215 case PROG_DEFAULT:
1216 {
1217 // V0.9.12 (2001-05-26) [umoeller]
1218 ULONG ulDosAppType;
1219 appQueryAppType(Details.pszExecutable,
1220 &ulDosAppType,
1221 &Details.progt.progc);
1222 }
1223 break;
1224 }
1225
1226 // set session type from option flags
1227 if (ulFlags & APP_RUN_FULLSCREEN)
1228 {
1229 if (Details.progt.progc == PROG_WINDOWABLEVIO)
1230 Details.progt.progc = PROG_FULLSCREEN;
1231 else if (Details.progt.progc == PROG_WINDOWEDVDM)
1232 Details.progt.progc = PROG_VDM;
1233 }
1234
1235 if (ulIsWinApp = appIsWindowsApp(Details.progt.progc))
1236 {
1237 if (ulFlags & APP_RUN_FULLSCREEN)
1238 Details.progt.progc = (ulFlags & APP_RUN_ENHANCED)
1239 ? PROG_31_ENH
1240 : PROG_31_STD;
1241 else
1242 {
1243 if (ulFlags & APP_RUN_STANDARD)
1244 Details.progt.progc = (ulFlags & APP_RUN_SEPARATE)
1245 ? PROG_31_STDSEAMLESSVDM
1246 : PROG_31_STDSEAMLESSCOMMON;
1247 else if (ulFlags & APP_RUN_ENHANCED)
1248 Details.progt.progc = (ulFlags & APP_RUN_SEPARATE)
1249 ? PROG_31_ENHSEAMLESSVDM
1250 : PROG_31_ENHSEAMLESSCOMMON;
1251 }
1252
1253 // re-run V0.9.16 (2001-10-19) [umoeller]
1254 ulIsWinApp = appIsWindowsApp(Details.progt.progc);
1255 }
1256
1257 /*
1258 * command lines fixups:
1259 *
1260 */
1261
1262 if (!strcmp(Details.pszExecutable, "*"))
1263 {
1264 /*
1265 * "*" for command sessions:
1266 *
1267 */
1268
1269 if (ulIsWinApp)
1270 {
1271 // cheat: WinStartApp doesn't support NULL
1272 // for Win-OS2 sessions, so manually start winos2.com
1273 Details.pszExecutable = "WINOS2.COM";
1274 // this is a DOS app, so fix this to DOS fullscreen
1275 Details.progt.progc = PROG_VDM;
1276
1277 if (ulIsWinApp == 2)
1278 {
1279 // enhanced Win-OS/2 session:
1280 PSZ psz = NULL;
1281 if (strParamsPatched.ulLength)
1282 // "/3 " + existing params
1283 psz = strdup(strParamsPatched.psz);
1284
1285 xstrcpy(&strParamsPatched, "/3 ", 0);
1286
1287 if (psz)
1288 {
1289 xstrcat(&strParamsPatched, psz, 0);
1290 free(psz);
1291 }
1292 }
1293 }
1294 else
1295 // for all other executable types
1296 // (including OS/2 and DOS sessions),
1297 // set pszExecutable to NULL; this will
1298 // have WinStartApp start a cmd shell
1299 Details.pszExecutable = NULL;
1300
1301 } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
1302
1303 // else
1304
1305 // no, this else breaks the WINOS2.COM hack above... we
1306 // need to look for that on the PATH as well
1307 // V0.9.20 (2002-07-03) [umoeller]
1308 if (Details.pszExecutable)
1309 {
1310 // check the executable and look for it on the
1311 // PATH if necessary
1312 if (!(arc = CheckAndQualifyExecutable(&Details,
1313 &strExecutablePatched)))
1314 {
1315 PSZ pszExtension;
1316
1317 // make sure startup dir is really a directory
1318 // V0.9.20 (2002-07-03) [umoeller]: moved this down
1319 if (Details.pszStartupDir)
1320 {
1321 ULONG ulAttr;
1322 // it is valid to specify a startup dir of "C:"
1323 if ( (strlen(Details.pszStartupDir) > 2)
1324 && (!(arc = doshQueryPathAttr(Details.pszStartupDir,
1325 &ulAttr)))
1326 && (!(ulAttr & FILE_DIRECTORY))
1327 )
1328 arc = ERROR_PATH_NOT_FOUND;
1329 }
1330
1331 // we frequently get here for BAT and CMD files
1332 // with progtype == PROG_DEFAULT, so include
1333 // that in the check, or all BAT files will fail
1334 // V0.9.20 (2002-07-03) [umoeller]
1335
1336 switch (Details.progt.progc)
1337 {
1338 /*
1339 * .CMD files fixups
1340 *
1341 */
1342
1343 case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller]
1344 case PROG_FULLSCREEN: // OS/2 fullscreen
1345 case PROG_WINDOWABLEVIO: // OS/2 window
1346 {
1347 if ( (pszExtension = doshGetExtension(Details.pszExecutable))
1348 && (!stricmp(pszExtension, "CMD"))
1349 )
1350 {
1351 arc = CallBatchCorrectly(&Details,
1352 &strExecutablePatched,
1353 &strParamsPatched,
1354 "OS2_SHELL",
1355 "CMD.EXE");
1356 }
1357 }
1358 break;
1359 }
1360
1361 switch (Details.progt.progc)
1362 {
1363 case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller]
1364 case PROG_VDM: // DOS fullscreen
1365 case PROG_WINDOWEDVDM: // DOS window
1366 {
1367 if ( (pszExtension = doshGetExtension(Details.pszExecutable))
1368 && (!stricmp(pszExtension, "BAT"))
1369 )
1370 {
1371 arc = CallBatchCorrectly(&Details,
1372 &strExecutablePatched,
1373 &strParamsPatched,
1374 // there is no environment variable
1375 // for the DOS shell
1376 NULL,
1377 "COMMAND.COM");
1378 }
1379 }
1380 break;
1381 } // end switch (Details.progt.progc)
1382 }
1383 }
1384
1385 if (!arc)
1386 {
1387 if ( (ulIsWinApp)
1388 && ( (Details.pszEnvironment == NULL)
1389 || (!strlen(Details.pszEnvironment))
1390 )
1391 )
1392 {
1393 // this is a windoze app, and caller didn't bother
1394 // to give us an environment:
1395 // we MUST set one then, or we'll get the strangest
1396 // errors, up to system hangs. V0.9.12 (2001-05-26) [umoeller]
1397
1398 DOSENVIRONMENT Env = {0};
1399
1400 // get standard WIN-OS/2 environment
1401 PSZ pszTemp;
1402 if (!(arc = appQueryDefaultWin31Environment(&pszTemp)))
1403 {
1404 if (!(arc = appParseEnvironment(pszTemp,
1405 &Env)))
1406 {
1407 // now override KBD_CTRL_BYPASS=CTRL_ESC
1408 if ( (!(arc = appSetEnvironmentVar(&Env,
1409 "KBD_CTRL_BYPASS=CTRL_ESC",
1410 FALSE))) // add last
1411 && (!(arc = appConvertEnvironment(&Env,
1412 &pszWinOS2Env, // freed at bottom
1413 NULL)))
1414 )
1415 Details.pszEnvironment = pszWinOS2Env;
1416
1417 appFreeEnvironment(&Env);
1418 }
1419
1420 free(pszTemp);
1421 }
1422 }
1423
1424 if (!arc)
1425 {
1426 // if no title is given, use the executable
1427 if (!Details.pszTitle)
1428 Details.pszTitle = Details.pszExecutable;
1429
1430 // make sure params have a leading space
1431 // V0.9.18 (2002-03-27) [umoeller]
1432 if (strParamsPatched.ulLength)
1433 {
1434 if (strParamsPatched.psz[0] != ' ')
1435 {
1436 XSTRING str2;
1437 xstrInit(&str2, 0);
1438 xstrcpy(&str2, " ", 1);
1439 xstrcats(&str2, &strParamsPatched);
1440 xstrcpys(&strParamsPatched, &str2);
1441 xstrClear(&str2);
1442 // we really need xstrInsert or something
1443 }
1444 Details.pszParameters = strParamsPatched.psz;
1445 }
1446 else
1447 // never pass null pointers
1448 Details.pszParameters = "";
1449
1450 // never pass null pointers
1451 if (!Details.pszIcon)
1452 Details.pszIcon = "";
1453
1454 // never pass null pointers
1455 if (!Details.pszStartupDir)
1456 Details.pszStartupDir = "";
1457
1458 }
1459 }
1460 }
1461
1462 /*
1463 * part 2:
1464 * pack the fixed PROGDETAILS fields
1465 */
1466
1467 if (!arc)
1468 {
1469 ULONG cb,
1470 cbTitle,
1471 cbExecutable,
1472 cbParameters,
1473 cbStartupDir,
1474 cbIcon,
1475 cbEnvironment;
1476
1477 #ifdef DEBUG_PROGRAMSTART
1478 _PmpfF((" new progc: 0x%lX", pcProgDetails->progt.progc));
1479 _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle)));
1480 _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable)));
1481 _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters)));
1482 _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon)));
1483 #endif
1484
1485 // allocate a chunk of tiled memory from OS/2 to make sure
1486 // this is aligned on a 64K memory (backed up by a 16-bit
1487 // LDT selector); if it is not, and the environment
1488 // crosses segments, it gets truncated!!
1489 cb = sizeof(PROGDETAILS);
1490 if (cbTitle = strhSize(Details.pszTitle))
1491 cb += cbTitle;
1492
1493 if (cbExecutable = strhSize(Details.pszExecutable))
1494 cb += cbExecutable;
1495
1496 if (cbParameters = strhSize(Details.pszParameters))
1497 cb += cbParameters;
1498
1499 if (cbStartupDir = strhSize(Details.pszStartupDir))
1500 cb += cbStartupDir;
1501
1502 if (cbIcon = strhSize(Details.pszIcon))
1503 cb += cbIcon;
1504
1505 if (cbEnvironment = appQueryEnvironmentLen(Details.pszEnvironment))
1506 cb += cbEnvironment;
1507
1508 if (cb > 60000) // to be on the safe side
1509 arc = ERROR_BAD_ENVIRONMENT; // 10;
1510 else
1511 {
1512 PPROGDETAILS pNewProgDetails;
1513 // alright, allocate the shared memory now
1514 if (!(arc = DosAllocSharedMem((PVOID*)&pNewProgDetails,
1515 NULL,
1516 cb,
1517 PAG_COMMIT | OBJ_GETTABLE | OBJ_TILE | PAG_EXECUTE | PAG_READ | PAG_WRITE)))
1518 {
1519 // and copy stuff
1520 PBYTE pThis;
1521
1522 memset(pNewProgDetails, 0, cb);
1523
1524 pNewProgDetails->Length = sizeof(PROGDETAILS);
1525
1526 pNewProgDetails->progt.progc = Details.progt.progc;
1527
1528 pNewProgDetails->progt.fbVisible = Details.progt.fbVisible;
1529 memcpy(&pNewProgDetails->swpInitial, &Details.swpInitial, sizeof(SWP));
1530
1531 // start copying into buffer right after PROGDETAILS
1532 pThis = (PBYTE)(pNewProgDetails + 1);
1533
1534 // handy macro to avoid typos
1535 #define COPY(id) if (cb ## id) { \
1536 memcpy(pThis, Details.psz ## id, cb ## id); \
1537 pNewProgDetails->psz ## id = pThis; \
1538 pThis += cb ## id; }
1539
1540 COPY(Title);
1541 COPY(Executable);
1542 COPY(Parameters);
1543 COPY(StartupDir);
1544 COPY(Icon);
1545 COPY(Environment);
1546
1547 *ppDetails = pNewProgDetails;
1548 }
1549 }
1550 }
1551
1552 xstrClear(&strParamsPatched);
1553 xstrClear(&strExecutablePatched);
1554
1555 if (pszWinOS2Env)
1556 free(pszWinOS2Env);
1557
1558 return arc;
1559}
1560
1561/*
1562 *@@ CallDosStartSession:
1563 *
1564 *@@added V0.9.18 (2002-03-27) [umoeller]
1565 */
1566
1567static APIRET CallDosStartSession(HAPP *phapp,
1568 const PROGDETAILS *pNewProgDetails, // in: program spec (req.)
1569 ULONG cbFailingName,
1570 PSZ pszFailingName)
1571{
1572 APIRET arc = NO_ERROR;
1573
1574 BOOL fCrit = FALSE,
1575 fResetDir = FALSE;
1576 CHAR szCurrentDir[CCHMAXPATH];
1577
1578 ULONG sid,
1579 pid;
1580 STARTDATA SData;
1581 SData.Length = sizeof(STARTDATA);
1582 SData.Related = SSF_RELATED_INDEPENDENT; // SSF_RELATED_CHILD;
1583 // per default, try to start this in the foreground
1584 SData.FgBg = SSF_FGBG_FORE;
1585 SData.TraceOpt = SSF_TRACEOPT_NONE;
1586
1587 SData.PgmTitle = pNewProgDetails->pszTitle;
1588 SData.PgmName = pNewProgDetails->pszExecutable;
1589 SData.PgmInputs = pNewProgDetails->pszParameters;
1590
1591 SData.TermQ = NULL;
1592 SData.Environment = pNewProgDetails->pszEnvironment;
1593 SData.InheritOpt = SSF_INHERTOPT_PARENT; // ignored
1594
1595 switch (pNewProgDetails->progt.progc)
1596 {
1597 case PROG_FULLSCREEN:
1598 SData.SessionType = SSF_TYPE_FULLSCREEN;
1599 break;
1600
1601 case PROG_WINDOWABLEVIO:
1602 SData.SessionType = SSF_TYPE_WINDOWABLEVIO;
1603 break;
1604
1605 case PROG_PM:
1606 SData.SessionType = SSF_TYPE_PM;
1607 SData.FgBg = SSF_FGBG_BACK; // otherwise we get ERROR_SMG_START_IN_BACKGROUND
1608 break;
1609
1610 case PROG_VDM:
1611 SData.SessionType = SSF_TYPE_VDM;
1612 break;
1613
1614 case PROG_WINDOWEDVDM:
1615 SData.SessionType = SSF_TYPE_WINDOWEDVDM;
1616 break;
1617
1618 default:
1619 SData.SessionType = SSF_TYPE_DEFAULT;
1620 }
1621
1622 SData.IconFile = 0;
1623 SData.PgmHandle = 0;
1624
1625 SData.PgmControl = 0;
1626
1627 if (pNewProgDetails->progt.fbVisible == SHE_VISIBLE)
1628 SData.PgmControl |= SSF_CONTROL_VISIBLE;
1629
1630 if (pNewProgDetails->swpInitial.fl & SWP_HIDE)
1631 SData.PgmControl |= SSF_CONTROL_INVISIBLE;
1632
1633 if (pNewProgDetails->swpInitial.fl & SWP_MAXIMIZE)
1634 SData.PgmControl |= SSF_CONTROL_MAXIMIZE;
1635 if (pNewProgDetails->swpInitial.fl & SWP_MINIMIZE)
1636 {
1637 SData.PgmControl |= SSF_CONTROL_MINIMIZE;
1638 // use background then
1639 SData.FgBg = SSF_FGBG_BACK;
1640 }
1641 if (pNewProgDetails->swpInitial.fl & SWP_MOVE)
1642 SData.PgmControl |= SSF_CONTROL_SETPOS;
1643 if (pNewProgDetails->swpInitial.fl & SWP_NOAUTOCLOSE)
1644 SData.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
1645
1646 SData.InitXPos = pNewProgDetails->swpInitial.x;
1647 SData.InitYPos = pNewProgDetails->swpInitial.y;
1648 SData.InitXSize = pNewProgDetails->swpInitial.cx;
1649 SData.InitYSize = pNewProgDetails->swpInitial.cy;
1650
1651 SData.Reserved = 0;
1652 SData.ObjectBuffer = pszFailingName;
1653 SData.ObjectBuffLen = cbFailingName;
1654
1655 // now, if a required module cannot be found,
1656 // DosStartSession still returns ERROR_FILE_NOT_FOUND
1657 // (2), but pszFailingName will be set to something
1658 // meaningful... so set it to a null string first
1659 // and we can then check if it has changed
1660 if (pszFailingName)
1661 *pszFailingName = '\0';
1662
1663 TRY_QUIET(excpt1)
1664 {
1665 if ( (pNewProgDetails->pszStartupDir)
1666 && (pNewProgDetails->pszStartupDir[0])
1667 )
1668 {
1669 fCrit = !DosEnterCritSec();
1670 if ( (!(arc = doshQueryCurrentDir(szCurrentDir)))
1671 && (!(arc = doshSetCurrentDir(pNewProgDetails->pszStartupDir)))
1672 )
1673 fResetDir = TRUE;
1674 }
1675
1676 if ( (!arc)
1677 && (!(arc = DosStartSession(&SData, &sid, &pid)))
1678 )
1679 {
1680 // app started:
1681 // compose HAPP from that
1682 *phapp = sid;
1683 }
1684 else if (pszFailingName && *pszFailingName)
1685 // DosStartSession has set this to something
1686 // other than NULL: then use error code 1804,
1687 // as cmd.exe does
1688 arc = 1804;
1689 }
1690 CATCH(excpt1)
1691 {
1692 arc = ERROR_PROTECTION_VIOLATION;
1693 } END_CATCH();
1694
1695 if (fResetDir)
1696 doshSetCurrentDir(szCurrentDir);
1697
1698 if (fCrit)
1699 DosExitCritSec();
1700
1701 #ifdef DEBUG_PROGRAMSTART
1702 _Pmpf((" DosStartSession returned %d, pszFailingName: \"%s\"",
1703 arc, pszFailingName));
1704 #endif
1705
1706 return arc;
1707}
1708
1709/*
1710 *@@ CallWinStartApp:
1711 * wrapper around WinStartApp which copies all the
1712 * parameters into a contiguous block of tiled memory.
1713 *
1714 * This might fix some of the problems with truncated
1715 * environments we were having because apparently the
1716 * WinStartApp thunking to 16-bit doesn't always work.
1717 *
1718 *@@added V0.9.18 (2002-02-13) [umoeller]
1719 *@@changed V0.9.18 (2002-03-27) [umoeller]: made failing modules work
1720 */
1721
1722static APIRET CallWinStartApp(HAPP *phapp, // out: application handle if NO_ERROR is returned
1723 HWND hwndNotify, // in: notify window or NULLHANDLE
1724 const PROGDETAILS *pcProgDetails, // in: program spec (req.)
1725 ULONG cbFailingName,
1726 PSZ pszFailingName)
1727{
1728 APIRET arc = NO_ERROR;
1729
1730 if (!pcProgDetails)
1731 return (ERROR_INVALID_PARAMETER);
1732
1733 if (pszFailingName)
1734 *pszFailingName = '\0';
1735
1736 if (!(*phapp = WinStartApp(hwndNotify,
1737 // receives WM_APPTERMINATENOTIFY
1738 (PPROGDETAILS)pcProgDetails,
1739 pcProgDetails->pszParameters,
1740 NULL, // "reserved", PMREF says...
1741 SAF_INSTALLEDCMDLINE)))
1742 // we MUST use SAF_INSTALLEDCMDLINE
1743 // or no Win-OS/2 session will start...
1744 // whatever is going on here... Warp 4 FP11
1745
1746 // do not use SAF_STARTCHILDAPP, or the
1747 // app will be terminated automatically
1748 // when the calling process terminates!
1749 {
1750 // cannot start app:
1751 PERRINFO pei;
1752
1753 #ifdef DEBUG_PROGRAMSTART
1754 _Pmpf((__FUNCTION__ ": WinStartApp failed"));
1755 #endif
1756
1757 // unfortunately WinStartApp doesn't
1758 // return meaningful codes like DosStartSession, so
1759 // try to see what happened
1760
1761 if (pei = WinGetErrorInfo(0))
1762 {
1763 #ifdef DEBUG_PROGRAMSTART
1764 _Pmpf((" WinGetErrorInfo returned 0x%lX, errorid 0x%lX, %d",
1765 pei,
1766 pei->idError,
1767 ERRORIDERROR(pei->idError)));
1768 #endif
1769
1770 switch (ERRORIDERROR(pei->idError))
1771 {
1772 case PMERR_DOS_ERROR: // (0x1200)
1773 {
1774 /*
1775 PUSHORT pausMsgOfs = (PUSHORT)(((PBYTE)pei) + pei->offaoffszMsg);
1776 PULONG pulData = (PULONG)(((PBYTE)pei) + pei->offBinaryData);
1777 PSZ pszMsg = (PSZ)(((PBYTE)pei) + *pausMsgOfs);
1778
1779 CHAR szMsg[1000];
1780 sprintf(szMsg, "cDetail: %d\nmsg: %s\n*pul: %d",
1781 pei->cDetailLevel,
1782 pszMsg,
1783 *(pulData - 1));
1784
1785 WinMessageBox(HWND_DESKTOP,
1786 NULLHANDLE,
1787 szMsg,
1788 "Error",
1789 0,
1790 MB_OK | MB_MOVEABLE);
1791
1792 // Very helpful. The message is "UNK 1200 E",
1793 // where I assume "UNK" means "unknown", which is
1794 // exactly what I was trying to find out. Oh my.
1795 // And cDetailLevel is always 1, which isn't terribly
1796 // helpful either. V0.9.18 (2002-03-27) [umoeller]
1797 // WHO THE &%õ$ CREATED THESE APIS?
1798
1799 */
1800
1801 // this is probably the case where the module
1802 // couldn't be loaded, so try DosStartSession
1803 // to get a meaningful return code... note that
1804 // this cannot handle hwndNotify then
1805 /* arc = CallDosStartSession(phapp,
1806 pcProgDetails,
1807 cbFailingName,
1808 pszFailingName); */
1809 arc = ERROR_FILE_NOT_FOUND;
1810 }
1811 break;
1812
1813 case PMERR_INVALID_APPL: // (0x1530)
1814 // Attempted to start an application whose type is not
1815 // recognized by OS/2.
1816 // This we get also if the executable doesn't exist...
1817 // V0.9.18 (2002-03-27) [umoeller]
1818 // arc = ERROR_INVALID_EXE_SIGNATURE;
1819 arc = ERROR_FILE_NOT_FOUND;
1820 break;
1821
1822 case PMERR_INVALID_PARAMETERS: // (0x1208)
1823 // An application parameter value is invalid for
1824 // its converted PM type. For example: a 4-byte
1825 // value outside the range -32 768 to +32 767 cannot be
1826 // converted to a SHORT, and a negative number cannot
1827 // be converted to a ULONG or USHORT.
1828 arc = ERROR_INVALID_DATA;
1829 break;
1830
1831 case PMERR_STARTED_IN_BACKGROUND: // (0x1532)
1832 // The application started a new session in the
1833 // background.
1834 arc = ERROR_SMG_START_IN_BACKGROUND;
1835 break;
1836
1837 case PMERR_INVALID_WINDOW: // (0x1206)
1838 // The window specified with a Window List call
1839 // is not a valid frame window.
1840
1841 default:
1842 arc = ERROR_BAD_FORMAT;
1843 break;
1844 }
1845
1846 WinFreeErrorInfo(pei);
1847 }
1848 }
1849
1850 return arc;
1851}
1852
1853/*
1854 *@@ appStartApp:
1855 * wrapper around WinStartApp which fixes the
1856 * specified PROGDETAILS to (hopefully) work
1857 * work with all executable types.
1858 *
1859 * This first calls appBuildProgDetails (see
1860 * remarks there) and then calls WinStartApp.
1861 *
1862 * Since this calls WinStartApp in turn, this
1863 * requires a message queue on the calling thread.
1864 *
1865 * Note that this also does minimal checking on
1866 * the specified parameters so it can return something
1867 * more meaningful than FALSE like WinStartApp.
1868 * As a result, you get a DOS error code now (V0.9.16).
1869 *
1870 * Most importantly:
1871 *
1872 * -- ERROR_INVALID_THREADID: not running on thread 1.
1873 * See remarks below.
1874 *
1875 * -- ERROR_NOT_ENOUGH_MEMORY
1876 *
1877 * plus the many error codes from appBuildProgDetails,
1878 * which gets called in turn.
1879 *
1880 * <B>About enforcing thread 1</B>
1881 *
1882 * OK, after long, long debugging hours, I have found
1883 * that WinStartApp hangs the system in the following
1884 * cases hard:
1885 *
1886 * -- If a Win-OS/2 session is started and WinStartApp
1887 * is _not_ on thread 1. For this reason, we check
1888 * if the caller is trying to start a Win-OS/2
1889 * session and return ERROR_INVALID_THREADID if
1890 * this is not running on thread 1.
1891 *
1892 * -- By contrast, there are many situations where
1893 * calling WinStartApp from within the Workplace
1894 * process will hang the system, most notably
1895 * with VIO sessions. I have been unable to figure
1896 * out why this happens, so XWorkplace now uses
1897 * its daemon to call WinStartApp instead.
1898 *
1899 * As a word of wisdom, do not call this from
1900 * within the Workplace process. For some strange
1901 * reason though, the XWorkplace "Run" dialog
1902 * (which uses this) _does_ work. Whatever.
1903 *
1904 *@@added V0.9.6 (2000-10-16) [umoeller]
1905 *@@changed V0.9.7 (2000-12-10) [umoeller]: PROGDETAILS.swpInitial no longer zeroed... this broke VIOs
1906 *@@changed V0.9.7 (2000-12-17) [umoeller]: PROGDETAILS.pszEnvironment no longer zeroed
1907 *@@changed V0.9.9 (2001-01-27) [umoeller]: crashed if PROGDETAILS.pszExecutable was NULL
1908 *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed PROG_DEFAULT
1909 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
1910 *@@changed V0.9.14 (2001-08-07) [pr]: removed some env. strings for Win. apps.
1911 *@@changed V0.9.14 (2001-08-23) [pr]: added session type options
1912 *@@changed V0.9.16 (2001-10-19) [umoeller]: added prototype to return APIRET
1913 *@@changed V0.9.16 (2001-10-19) [umoeller]: added thread-1 check
1914 *@@changed V0.9.16 (2001-12-06) [umoeller]: now using doshSearchPath for finding pszExecutable if not qualified
1915 *@@changed V0.9.16 (2002-01-04) [umoeller]: removed error report if startup directory was drive letter only
1916 *@@changed V0.9.16 (2002-01-04) [umoeller]: added more detailed error reports and *FailingName params
1917 *@@changed V0.9.18 (2002-02-13) [umoeller]: added CallWinStartApp to fix possible memory problems
1918 *@@changed V0.9.18 (2002-03-27) [umoeller]: no longer returning ERROR_INVALID_THREADID, except for Win-OS/2 sessions
1919 *@@changed V0.9.18 (2002-03-27) [umoeller]: extracted appBuildProgDetails
1920 *@@changed V0.9.19 (2002-03-28) [umoeller]: adjusted for new appBuildProgDetails
1921 */
1922
1923APIRET appStartApp(HWND hwndNotify, // in: notify window or NULLHANDLE
1924 const PROGDETAILS *pcProgDetails, // in: program spec (req.)
1925 ULONG ulFlags, // in: APP_RUN_* flags or 0
1926 HAPP *phapp, // out: application handle if NO_ERROR is returned
1927 ULONG cbFailingName,
1928 PSZ pszFailingName)
1929{
1930 APIRET arc;
1931
1932 PPROGDETAILS pDetails;
1933
1934 if (!phapp)
1935 return (ERROR_INVALID_PARAMETER);
1936
1937 if (!(arc = appBuildProgDetails(&pDetails,
1938 pcProgDetails,
1939 ulFlags)))
1940 {
1941 if (pszFailingName)
1942 strhncpy0(pszFailingName, pDetails->pszExecutable, cbFailingName);
1943
1944 if ( (appIsWindowsApp(pDetails->progt.progc))
1945 && (doshMyTID() != 1) // V0.9.16 (2001-10-19) [umoeller]
1946 )
1947 arc = ERROR_INVALID_THREADID;
1948 else
1949 arc = CallWinStartApp(phapp,
1950 hwndNotify,
1951 pDetails,
1952 cbFailingName,
1953 pszFailingName);
1954
1955 DosFreeMem(pDetails);
1956
1957 } // end if (ProgDetails.pszExecutable)
1958
1959 #ifdef DEBUG_PROGRAMSTART
1960 _Pmpf((__FUNCTION__ ": returning %d", arc));
1961 #endif
1962
1963 return arc;
1964}
1965
1966/*
1967 *@@ appWaitForApp:
1968 * waits for the specified application to terminate
1969 * and returns its exit code.
1970 *
1971 *@@added V0.9.9 (2001-03-07) [umoeller]
1972 */
1973
1974BOOL appWaitForApp(HWND hwndNotify, // in: notify window
1975 HAPP happ, // in: app to wait for
1976 PULONG pulExitCode) // out: exit code (ptr can be NULL)
1977{
1978 BOOL brc = FALSE;
1979
1980 if (happ)
1981 {
1982 // app started:
1983 // enter a modal message loop until we get the
1984 // WM_APPTERMINATENOTIFY for happ. Then we
1985 // know the app is done.
1986 HAB hab = WinQueryAnchorBlock(hwndNotify);
1987 QMSG qmsg;
1988 // ULONG ulXFixReturnCode = 0;
1989 while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
1990 {
1991 if ( (qmsg.msg == WM_APPTERMINATENOTIFY)
1992 && (qmsg.hwnd == hwndNotify)
1993 && (qmsg.mp1 == (MPARAM)happ)
1994 )
1995 {
1996 // xfix has terminated:
1997 // get xfix return code from mp2... this is:
1998 // -- 0: everything's OK, continue.
1999 // -- 1: handle section was rewritten, restart Desktop
2000 // now.
2001 if (pulExitCode)
2002 *pulExitCode = (ULONG)qmsg.mp2;
2003 brc = TRUE;
2004 // do not dispatch this
2005 break;
2006 }
2007
2008 WinDispatchMsg(hab, &qmsg);
2009 }
2010 }
2011
2012 return brc;
2013}
2014
2015/*
2016 *@@ appQuickStartApp:
2017 * shortcut for simply starting an app and
2018 * waiting until it's finished.
2019 *
2020 * On errors, NULLHANDLE is returned.
2021 *
2022 * If pulReturnCode != NULL, it receives the
2023 * return code of the app.
2024 *
2025 *@@added V0.9.16 (2001-10-19) [umoeller]
2026 */
2027
2028HAPP appQuickStartApp(const char *pcszFile,
2029 ULONG ulProgType, // e.g. PROG_PM
2030 const char *pcszArgs,
2031 PULONG pulExitCode)
2032{
2033 PROGDETAILS pd = {0};
2034 HAPP happ,
2035 happReturn = NULLHANDLE;
2036 CHAR szDir[CCHMAXPATH] = "";
2037 PCSZ p;
2038 HWND hwndObject;
2039
2040 pd.Length = sizeof(pd);
2041 pd.progt.progc = ulProgType;
2042 pd.progt.fbVisible = SHE_VISIBLE;
2043 pd.pszExecutable = (PSZ)pcszFile;
2044 pd.pszParameters = (PSZ)pcszArgs;
2045 if (p = strrchr(pcszFile, '\\'))
2046 {
2047 strhncpy0(szDir,
2048 pcszFile,
2049 p - pcszFile);
2050 pd.pszStartupDir = szDir;
2051 }
2052
2053 if ( (hwndObject = winhCreateObjectWindow(WC_STATIC, NULL))
2054 && (!appStartApp(hwndObject,
2055 &pd,
2056 0,
2057 &happ,
2058 0,
2059 NULL))
2060 )
2061 {
2062 if (appWaitForApp(hwndObject,
2063 happ,
2064 pulExitCode))
2065 happReturn = happ;
2066 }
2067
2068 return happReturn;
2069}
Note: See TracBrowser for help on using the repository browser.