Show: Delphi C++
Display Preferences

#pragma exit and #pragma startup

From RAD Studio XE3
Jump to: navigation, search

Go Up to Pragma Directives Overview Index

Contents

Syntax (See Pseudo-grammar)

#pragma startup FUNC [NN]
#pragma exit FUNC [NN]

Description

These two pragmas allow the program to specify function(s) that should be called either upon program startup (before the main function is called) or program exit (just before the program terminates through _exit).

The specified function name must be a previously declared function taking no arguments and returning void; in other words, it should be declared as:

void myfunc(void);

Then the #pragma would be:

#pragma startup myfunc

Specifying Priority

The optional priority parameter (NN) should be an integer in the range from 64 through 255. The highest priority is 0. Functions with higher priorities are called first at startup and last at exit. If you do not specify a priority, it defaults to 30 for BCC32 or 100 for BCC64.

Specifying Exit Priority in 64-bit Windows Applications

Using the #pragma startup/exit directives without a specified priority is not recommended. Doing this in a VCL application causes exit routines to run after the main form is closed for BCC32, but for BCC64, the routines are executed before the main form closes. If you are using BCC64, you must specify the #pragma exit routine with priority 30 in order to guarantee that the exit routine runs after __ExitVCL (and to match the behavior of BCC32). For example:

 #pragma exit myfunc 30
Warning: Do not use priority values less than 64. Priorities from 0 through 63 are reserved for ISO startup and shutdown mechanisms. The exception for BCC64 is described in the text above.

See Also

Personal tools
Previous Versions
In other languages