aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/slept/sleepold.cpp
blob: fb3abdd4f86b20b329d8a32aac4ddf3dd70f4ff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//////////////////////////////////////////////////////////////////////////////
//
//  Detour Test Program (sleepold.cpp of sleepold.exe)
//
//  Microsoft Research Detours Package
//
//  Copyright (c) Microsoft Corporation.  All rights reserved.
//

#include <windows.h>
#include <stdio.h>

#include "verify.cpp"

int __cdecl main(int argc, char **argv)
{
    BOOL fQuiet = FALSE;

    if (argc == 2 && _stricmp(argv[1], "-quiet") == 0) {
        fQuiet = TRUE;
    }

    //
    // Verify what the code looks like.
    //
    printf("sleepold.exe: Starting (at %p).\n", main);
    if (!fQuiet) {
        Verify("SleepEx", (PBYTE)SleepEx);
        printf("\n");
    }
    fflush(stdout);

    //
    // See if another process wants us to wait on a shared event.
    // This helps in testing loading a DLL into a new process.

    if (argc == 2 && _stricmp(argv[1], "-wait") == 0) {
        HANDLE hEvent = OpenEventA(SYNCHRONIZE, FALSE, "detours_load_test_event");
        if (hEvent) {
            printf("sleepold.exe: Waiting for detours_load_test_event to be set.\n");
            fflush(stdout);
            WaitForSingleObject(hEvent, INFINITE);
        }
        else {
            printf("sleepold.exe: Couldn't open detours_load_test_event.\n");
        }
    }

    //
    // Try out sleep (which may be detours).
    //
    printf("sleepold.exe: Calling Sleep for 1 second.\n");
    Sleep(1000);

    printf("sleepold.exe: Calling SleepEx for 1 second.\n");
    SleepEx(1000, false);

    printf("sleepold.exe: Calling Sleep again for 1 second.\n");
    Sleep(1000);

    // DebugBreak();

    printf("sleepold.exe: Done sleeping.\n\n");
    fflush(stdout);

    return 0;
}
//
///////////////////////////////////////////////////////////////// End of File.