1 | // Licensed to the .NET Foundation under one or more agreements. |
---|---|
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | #include <stdio.h> |
6 | #include <xplatform.h> |
7 | |
8 | typedef BOOL(__stdcall *HandleCallback)(void*); |
9 | |
10 | extern "C"DLL_EXPORT size_t __stdcall In(void* handle, HandleCallback handleCallback) |
11 | { |
12 | if (handleCallback != nullptr && !handleCallback(handle)) |
13 | { |
14 | return (size_t)(-1); |
15 | } |
16 | |
17 | return reinterpret_cast<size_t>(handle); |
18 | } |
19 | |
20 | extern "C"DLL_EXPORT void* __stdcall Ret(void* handleValue) |
21 | { |
22 | return handleValue; |
23 | } |
24 | |
25 | extern "C"DLL_EXPORT void __stdcall Out(void* handleValue, void** pHandle) |
26 | { |
27 | if (pHandle == nullptr) |
28 | { |
29 | return; |
30 | } |
31 | |
32 | *pHandle = handleValue; |
33 | } |
34 | |
35 | extern "C"DLL_EXPORT size_t __stdcall Ref(void** pHandle, HandleCallback handleCallback) |
36 | { |
37 | if (handleCallback != nullptr && !handleCallback(*pHandle)) |
38 | { |
39 | return (size_t)(-1); |
40 | } |
41 | |
42 | return reinterpret_cast<size_t>(*pHandle); |
43 | } |
44 | |
45 | extern "C"DLL_EXPORT size_t __stdcall RefModify(void* handleValue, void** pHandle, HandleCallback handleCallback) |
46 | { |
47 | if (handleCallback != nullptr && !handleCallback(*pHandle)) |
48 | { |
49 | return (size_t)(-1); |
50 | } |
51 | |
52 | void* originalHandle = *pHandle; |
53 | |
54 | *pHandle = handleValue; |
55 | |
56 | return reinterpret_cast<size_t>(originalHandle); |
57 | } |
58 | |
59 | typedef void(__stdcall *InCallback)(void*); |
60 | |
61 | extern "C"DLL_EXPORT void __stdcall InvokeInCallback(InCallback callback, void* handle) |
62 | { |
63 | callback(handle); |
64 | } |
65 | |
66 | typedef void(__stdcall *RefCallback)(void**); |
67 | |
68 | extern "C"DLL_EXPORT void __stdcall InvokeRefCallback(RefCallback callback, void** pHandle) |
69 | { |
70 | callback(pHandle); |
71 | } |
72 | |
73 | typedef void*(__stdcall *RetCallback)(); |
74 | |
75 | extern "C"DLL_EXPORT void* __stdcall InvokeRetCallback(RetCallback callback) |
76 | { |
77 | return callback(); |
78 | } |
79 |