|
1 | 1 | ---
|
2 |
| -title: "/Gh (Enable _penter Hook Function)" |
3 |
| -ms.date: "11/04/2016" |
| 2 | +title: "/Gh (Enable _penter hook function)" |
| 3 | +description: "Describes the /Gh compiler option to call the supplied _penter function." |
| 4 | +ms.date: "07/06/2020" |
4 | 5 | f1_keywords: ["_penter"]
|
5 | 6 | helpviewer_keywords: ["/Gh compiler option [C++]", "Gh compiler option [C++]", "_penter function", "-Gh compiler option [C++]"]
|
6 | 7 | ms.assetid: 1510a082-8a0e-486e-a309-6add814b494f
|
7 | 8 | ---
|
8 |
| -# /Gh (Enable _penter Hook Function) |
| 9 | +# /Gh (Enable _penter hook function) |
9 | 10 |
|
10 | 11 | Causes a call to the `_penter` function at the start of every method or function.
|
11 | 12 |
|
12 | 13 | ## Syntax
|
13 | 14 |
|
14 |
| -``` |
15 |
| -/Gh |
16 |
| -``` |
| 15 | +> **`/Gh`** |
17 | 16 |
|
18 | 17 | ## Remarks
|
19 | 18 |
|
20 |
| -The `_penter` function is not part of any library and it is up to you to provide a definition for `_penter`. |
| 19 | +The `_penter` function isn't part of any library. It's up to you to provide a definition for `_penter`. |
21 | 20 |
|
22 |
| -Unless you plan to explicitly call `_penter`, you do not need to provide a prototype. The function must appear as if it had the following prototype, and it must push the content of all registers on entry and pop the unchanged content on exit: |
| 21 | +Unless you plan to explicitly call `_penter`, you don't need to provide a prototype. The function must push the content of all registers on entry and pop the unchanged content on exit. It must appear as if it had the following prototype: |
23 | 22 |
|
24 | 23 | ```cpp
|
25 | 24 | void __declspec(naked) __cdecl _penter( void );
|
26 | 25 | ```
|
27 | 26 |
|
28 |
| -This declaration is not available for 64-bit projects. |
| 27 | +This declaration isn't available for 64-bit projects. |
29 | 28 |
|
30 | 29 | ### To set this compiler option in the Visual Studio development environment
|
31 | 30 |
|
32 | 31 | 1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
|
33 | 32 |
|
34 |
| -1. Click the **C/C++** folder. |
35 |
| -
|
36 |
| -1. Click the **Command Line** property page. |
| 33 | +1. Open the **Configuration Properties** > **C/C++** > **Command Line** property page. |
37 | 34 |
|
38 |
| -1. Type the compiler option in the **Additional Options** box. |
| 35 | +1. Enter the compiler option in the **Additional Options** box. |
39 | 36 |
|
40 | 37 | ### To set this compiler option programmatically
|
41 | 38 |
|
42 | 39 | - See <xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.AdditionalOptions%2A>.
|
43 | 40 |
|
44 | 41 | ## Example
|
45 | 42 |
|
46 |
| -The following code, when compiled with **/Gh**, shows how `_penter` is called twice; once when entering function `main` and once when entering function `x`. |
| 43 | +The following code, when compiled with **/Gh**, shows how `_penter` is called twice; once when entering function `main` and once when entering function `x`. The example consists of two source files, which you compile separately. |
47 | 44 |
|
48 | 45 | ```cpp
|
49 |
| -// Gh_compiler_option.cpp |
50 |
| -// compile with: /Gh |
| 46 | +// local_penter.cpp |
| 47 | +// compile with: cl /EHsc /c local_penter.cpp |
51 | 48 | // processor: x86
|
52 | 49 | #include <stdio.h>
|
53 |
| -void x() {} |
54 |
| -
|
55 |
| -int main() { |
56 |
| - x(); |
57 |
| -} |
58 | 50 |
|
59 | 51 | extern "C" void __declspec(naked) __cdecl _penter( void ) {
|
60 | 52 | _asm {
|
@@ -82,12 +74,29 @@ extern "C" void __declspec(naked) __cdecl _penter( void ) {
|
82 | 74 | }
|
83 | 75 | ```
|
84 | 76 |
|
| 77 | +```cpp |
| 78 | +// Gh_compiler_option.cpp |
| 79 | +// compile with: cl /EHsc /Gh Gh_compiler_option.cpp local_penter.obj |
| 80 | +// processor: x86 |
| 81 | +#include <stdio.h> |
| 82 | + |
| 83 | +void x() {} |
| 84 | + |
| 85 | +int main() { |
| 86 | + x(); |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +When run, the local `_penter` function is called on entry to `main` and `x`: |
| 91 | + |
85 | 92 | ```Output
|
| 93 | +
|
86 | 94 | In a function!
|
87 | 95 | In a function!
|
88 | 96 | ```
|
89 | 97 |
|
90 | 98 | ## See also
|
91 | 99 |
|
92 |
| -[MSVC Compiler Options](compiler-options.md)<br/> |
93 |
| -[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md) |
| 100 | +[MSVC compiler options](compiler-options.md)<br/> |
| 101 | +[MSVC compiler command-line syntax](compiler-command-line-syntax.md)<br/> |
| 102 | +[`/GH` (Enable _pexit hook function)](gh-enable-pexit-hook-function.md) |
0 commit comments