1


/**/
/***
2
*crt0.c – C runtime initialization routine
3
*
4
* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
5
*
6
*Purpose:
7
* This the actual startup routine for apps. It calls the user's main
8
* routine [w]main() or [w]WinMain after performing C Run-Time Library
9
* initialization.
10
*
11
* (With ifdef's, this source file also provides the source code for
12
* wcrt0.c, the startup routine for console apps with wide characters,
13
* wincrt0.c, the startup routine for Windows apps, and wwincrt0.c,
14
* the startup routine for Windows apps with wide characters.)
15
*
16
*******************************************************************************/
17

18
#ifdef _WIN32
19

20
#ifndef CRTDLL
21

22
#include
<
cruntime.h
>
23
#include
<
dos.h
>
24
#include
<
internal
.h
>
25
#include
<
stdlib.h
>
26
#include
<
string
.h
>
27
#include
<
rterr.h
>
28
#include
<
windows.h
>
29
#include
<
awint.h
>
30
#include
<
tchar.h
>
31
#include
<
dbgint.h
>
32

33


/**/
/*
34
* wWinMain is not yet defined in winbase.h. When it is, this should be
35
* removed.
36
*/
37

38

int
39
WINAPI
40
wWinMain(
41
HINSTANCE hInstance,
42
HINSTANCE hPrevInstance,
43
LPWSTR lpCmdLine,
44
int
nShowCmd
45
);
46

47
#ifdef WPRFLAG
48
_TUCHAR
*
__cdecl _wwincmdln(
void
);
49

#else
/* WPRFLAG */
50
_TUCHAR
*
__cdecl _wincmdln(
void
);
51

#endif
/* WPRFLAG */
52

53


/**/
/*
54
* command line, environment, and a few other globals
55
*/
56

57
#ifdef WPRFLAG
58

wchar_t
*
_wcmdln;
/**/
/* points to wide command line */
59

#else
/* WPRFLAG */
60


char
*
_acmdln;
/**/
/* points to command line */
61

#endif
/* WPRFLAG */
62

63


char
*
_aenvptr
=
NULL;
/**/
/* points to environment block */
64

wchar_t
*
_wenvptr
=
NULL;
/**/
/* points to wide environment block */
65

66

67


void
(__cdecl
*
_aexit_rtn)(
int
)
=
_exit;
/**/
/* RT message return procedure */
68

69


static
void
__cdecl fast_error_exit(
int
);
/**/
/* Error exit via ExitProcess */
70

71


/**/
/*
72
* _error_mode and _apptype, together, determine how error messages are
73
* written out.
74
*/
75

int
__error_mode
=
_OUT_TO_DEFAULT;
76
#ifdef _WINMAIN_
77

int
__app_type
=
_GUI_APP;
78

#else
/* _WINMAIN_ */
79

int
__app_type
=
_CONSOLE_APP;
80

#endif
/* _WINMAIN_ */
81

82

83


/**/
/***
84
*BaseProcessStartup(PVOID Peb)
85
*
86
*Purpose:
87
* This routine does the C runtime initialization, calls main(), and
88
* then exits. It never returns.
89
*
90
*Entry:
91
* PVOID Peb – pointer to Win32 Process Environment Block (not used)
92
*
93
*Exit:
94
* This function never returns.
95
*
96
*******************************************************************************/
97

98
#ifdef _WINMAIN_
99

100
#ifdef WPRFLAG
101

void
wWinMainCRTStartup(
102

#else
/* WPRFLAG */
103

void
WinMainCRTStartup(
104

#endif
/* WPRFLAG */
105

106

#else
/* _WINMAIN_ */
107

108
#ifdef WPRFLAG
109

void
wmainCRTStartup(
110

#else
/* WPRFLAG */
111

void
mainCRTStartup(
112

#endif
/* WPRFLAG */
113

114

#endif
/* _WINMAIN_ */
115
void
116
)
117

118



212
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
213
/**//* end of try – except */
220
221
}
222

223

224

225


/**/
/***
226
*_amsg_exit(rterrnum) – Fast exit fatal errors
227
*
228
*Purpose:
229
* Exit the program with error code of 255 and appropriate error
230
* message.
231
*
232
*Entry:
233
* int rterrnum – error message number (amsg_exit only).
234
*
235
*Exit:
236
* Calls exit() (for integer divide-by-0) or _exit() indirectly
237
* through _aexit_rtn [amsg_exit].
238
* For multi-thread: calls _exit() function
239
*
240
*Exceptions:
241
*
242
*******************************************************************************/
243

244

void
__cdecl _amsg_exit (
245
int
rterrnum
246
)
247



258

259


/**/
/***
260
*fast_error_exit(rterrnum) – Faster exit fatal errors
261
*
262
*Purpose:
263
* Exit the process with error code of 255 and appropriate error
264
* message.
265
*
266
*Entry:
267
* int rterrnum – error message number (amsg_exit only).
268
*
269
*Exit:
270
* Calls ExitProcess.
271
*
272
*Exceptions:
273
*
274
*******************************************************************************/
275

276

static
void
__cdecl fast_error_exit (
277
int
rterrnum
278
)
279



290

291
#ifndef WPRFLAG
292

293

294

#endif
/* WPRFLAG */
295

296

#endif
/* CRTDLL */
297

298

#else
/* _WIN32 */
299

300
#include
<
cruntime.h
>
301
#include
<
internal
.h
>
302
#include
<
stdlib.h
>
303
#include
<
msdos.h
>
304
#include
<
string
.h
>
305
#include
<
setjmp.h
>
306
#include
<
dbgint.h
>
307
#include
<
macos ypes.h
>
308
#include
<
macossegload.h
>
309
#include
<
macosgestalte.h
>
310
#include
<
macososutils.h
>
311
#include
<
macos raps.h
>
312
#include
<
mpw.h
>
313

314


static
void
__cdecl Inherit(
void
);
/**/
/* local function */
315

316


int
__cdecl main(
int
,
char
**
,
char
**
);
/**/
/*generated by compiler*/
317

318
unsigned
long
_GetShellStack(
void
);
319

320

static
char
*
__cdecl _p2cstr_internal ( unsigned
char
*
str );
321

322

extern
MPWBLOCK
*
_pMPWBlock;
323

extern
int
__argc;
324

extern
char
**
__argv;
325

326


/**/
/***
327
*__crt0()
328
*
329
*Purpose:
330
* This routine does the C runtime initialization, calls main(), and
331
* then exits. It never returns.
332
*
333
*Entry:
334
*
335
*Exit:
336
* This function never returns.
337
*
338
*******************************************************************************/
339

340

void
__cdecl __crt0 (
341
)
342



359
}
360
361
#endif /* _M_MPPC */
362
363
_environ = NULL;
364
if (_pMPWBlock == NULL) 
376
#ifndef _M_MPPC
377
else 
385
#endif /* _M_MPPC */
386
387
/**//*
388
* call run time initializer
389
*/
390
__cinit();
391
392
mainret = main(__argc, __argv, _environ);
393
exit(mainret);
394
}
395

396

397
#ifndef _M_MPPC
398


/**/
/***
399
*Inherit() – obtain and process info on inherited file handles.
400
*
401
*Purpose:
402
*
403
* Locates and interprets MPW std files. For files we just save the
404
* file handles. For the console we save the device table address so
405
* we can do console I/O. In the latter case, FDEV is set in the _osfile
406
* array.
407
*
408
*Entry:
409
* Address of MPW param table
410
*
411
*Exit:
412
* No return value.
413
*
414
*Exceptions:
415
*
416
*******************************************************************************/
417

418

static
void
__cdecl Inherit (
419
void
420
)
421



428
for (i = 0; i < 3; i++) 
440
pFile++;
441
}
442
}
443

444

#endif
/* _M_MPPC */
445

446

447

448

static
char
*
__cdecl _p2cstr_internal (
449
unsigned
char
*
str
450
)
451



463
464
*pchDst = '0';
465
}
466
467
return( str );
468
}
469

470

#endif
/* _WIN32 */
471

mrxa是什么感染C语言开发总结(二十七)
未经允许不得转载:上海聚慕医疗器械有限公司 » mrxa是什么感染C语言开发总结(二十七)











