/Gh (Enable _penter hook function)
Causes a call to the _penter
function at the start of every method or function.
Syntax
/Gh
Remarks
The _penter
function isn't part of any library. It's up to you to provide a definition for _penter
.
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:
void __declspec(naked) __cdecl _penter( void );
This declaration isn't available for 64-bit projects.
To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.
Select the Configuration Properties > C/C++ > Command Line property page.
Enter the compiler option in the Additional Options box.
To set this compiler option programmatically
- See AdditionalOptions.
Example
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.
Source file local_penter.cpp
:
// local_penter.cpp
// compile with: cl /EHsc /c local_penter.cpp
// processor: x86
#include <stdio.h>
extern "C" void __declspec(naked) __cdecl _penter( void ) {
_asm {
push eax
push ebx
push ecx
push edx
push ebp
push edi
push esi
}
printf_s("\nIn a function!");
_asm {
pop esi
pop edi
pop ebp
pop edx
pop ecx
pop ebx
pop eax
ret
}
}
Source file Gh_compiler_option.cpp
:
// Gh_compiler_option.cpp
// compile with: cl /EHsc /Gh Gh_compiler_option.cpp local_penter.obj
// processor: x86
#include <stdio.h>
void x() {}
int main() {
x();
}
When run, the local _penter
function is called on entry to main
and x
:
In a function!
In a function!
See also
MSVC compiler options
MSVC compiler command-line syntax
/GH
(Enable _pexit hook function)
Feedback
https://aka.ms/ContentUserFeedback.
În curând: Pe parcursul anului 2024, vom elimina treptat Probleme legate de GitHub ca mecanism de feedback pentru conținut și îl vom înlocui cu un nou sistem de feedback. Pentru mai multe informații, consultați:Trimiteți și vizualizați feedback pentru