Embarcadero Builder C++ XE5 data execution prevention compiler

413 views Asked by At

Hope this isn't an obvious issue. I've recently run in exceptions due to a lack of Data Execution Prevention (DEP) support in our 32-bit exe on a Windows 2008 R2 server. Adding the exe to the DEP exclusion list, solved the issue as a workaround.

I would like to compile with support for DEP, but can't find any indication on how to do this in Builder XE5 c++. Is this possible? I have found some vague suggestions for Delphi, but nothing definitive.

Any ideas?

1

There are 1 answers

1
Remy Lebeau On

AFAIK, C++Builder doesn't have the same DEP options that Delphi has. You will have to either

  1. use an external PE editor to modify the PE flags of your compiled EXE file.

  2. call SetProcessDEPPolicy() at runtime, such as at the top of your main()/Winmain() function:

    void EnableDEP()
    {
        const DWORD PROCESS_DEP_ENABLE = 0x00000001;
        typedef BOOL WINAPI (*LP_SPDEPP)(DWORD);
    
        LP_SPDEPP SetProcessDEPPolicy = (LP_SPDEPP) GetProcAddress(GetModuleHandle(TEXT("kernel32")), "SetProcessDEPPolicy");
        if (SetProcessDEPPolicy != NULL)
            SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
    }
    
    
    int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        EnableDEP();
        ...
    }