-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample.cpp
99 lines (79 loc) · 1.82 KB
/
example.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#define AFTER 1
#define BEFORE !AFTER
#include <string>
#include <tuple>
#include <iostream>
#include "hidecall.h"
#if BEFORE
static std::tuple<int, char> __stdcall getTuple();
class Base
{
public:
virtual int print(const char* str, int a) const = 0;
};
class Derived : public Base
{
public:
int print(const char* str, int a = 1) const override;
static void __cdecl welcome()
{
std::cout << "HI!\n";
}
virtual void virt()
{
std::cout << "Virtual\n";
}
};
int Derived::print(const char* str, int a) const
{
std::cout << str << ' ' << a << std::endl;
return 1;
}
static std::tuple<int, char> __stdcall getTuple()
{
return std::make_tuple(-15, 'F');
}
#endif
#if AFTER
HIDECALL_DECLARE(static, PACK(std::tuple<int, char> __stdcall), getTuple, ())
class Base
{
public:
virtual int print(const char* str, int a) const = 0;
};
class Derived : public Base
{
public:
HIDECALL_DECLARE(, int, print,(const char* str, int a = 1) const); // note you can't use "override" keyword
HIDECALL_CLASS(static, void __cdecl, welcome, ())
{
std::cout << "HI!\n";
}
virtual HIDECALL_CLASS(, void, virt, ()) // note "virtual" is before macro, because "virtual" keyword applies only to one function.
{
std::cout << "Virtual\n";
}
};
HIDECALL_CLASS(, int, Derived::print, (const char* str, int a) const)
{
std::cout << str << ' ' << a << std::endl;
return 1;
}
HIDECALL(static, PACK(std::tuple<int, char> __stdcall), getTuple, ())
{
return std::make_tuple(-15, 'F');
}
#endif
// There is no need to modify calls in the code after using HIDECALL
int main()
{
Derived d;
Base* b = &d;
Derived* pD = &d;
b->print("Hello!", 7);
Derived::welcome();
pD->virt();
auto [i, c] = getTuple();
std::cin.get();
return i + c;
}