/Gh (Enable __penter Hook Function)

/Gh

This option causes a call to the __penter function at the start of every method or function. The __penter function is not part of any library and it is up to you to provide a definition for __penter. Use assembly language to write the function.

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:

void __declspec(naked) _cdecl _penter( void );

The following code, when compiled with /Gh shows how __penter is called twice; once when entering function main and x and once when entering function x.

#include "stdio.h"

void x(){ }

void main() {
x();
}

void __declspec(naked) _cdecl _penter( void ) {
    _asm {
        push eax
        push ebx
        push ecx
        push edx
        push ebp
        push edi
        push esi
    }

printf("\nIn a function!");

    _asm {
        pop esi
        pop edi
        pop ebp
        pop edx
        pop ecx
        pop ebx
        pop eax
        ret
    }
}

IDE Settings (Project Settings dialog box)

Tab Category Control Setting
C/C++ C/C++ Language Project Options Type /Gh in the text box.