PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 22ms app.codeStats 0ms

/mordor/runtime_linking.h

http://github.com/mozy/mordor
C Header | 59 lines | 52 code | 6 blank | 1 comment | 1 complexity | b818f79f1a1b460f14232a49f850025f MD5 | raw file
 1#ifndef __MORDOR_RUNTIME_LINKING_H__
 2#define __MORDOR_RUNTIME_LINKING_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include <dbghelp.h>
 6#include <IPHlpApi.h>
 7#include <lm.h>
 8#include <winhttp.h>
 9#include <winsock2.h>
10#include <ws2tcpip.h>
11
12#define MORDOR_RUNTIME_LINK_DECLARATION(Name, ReturnType, CallingConvention, ArgTypes) \
13    typedef ReturnType (CallingConvention * LPFN_##Name) ArgTypes;              \
14    extern LPFN_##Name p##Name;
15
16#define MORDOR_RUNTIME_LINK_DEFINITION(Name, ReturnType, CallingConvention, ArgTypes, Args, Library)\
17    static ReturnType CallingConvention Name##NotImpl ArgTypes;                 \
18    static ReturnType CallingConvention Name##Thunk ArgTypes                    \
19    {                                                                           \
20        HINSTANCE hInstance = LoadLibraryW(Library);                            \
21        p##Name = (LPFN_##Name)GetProcAddress(hInstance, #Name);                \
22        if (!p##Name)                                                           \
23            p##Name = &Name##NotImpl;                                           \
24        return p##Name Args;                                                    \
25    }                                                                           \
26    LPFN_##Name p##Name = &Name##Thunk;                                         \
27    static ReturnType CallingConvention Name##NotImpl ArgTypes
28
29namespace Mordor {
30
31MORDOR_RUNTIME_LINK_DECLARATION(CancelIoEx, BOOL, WINAPI, (HANDLE, LPOVERLAPPED));
32MORDOR_RUNTIME_LINK_DECLARATION(ConvertFiberToThread, BOOL, WINAPI, (VOID));
33MORDOR_RUNTIME_LINK_DECLARATION(CreateFiberEx, LPVOID, WINAPI, (SIZE_T, SIZE_T, DWORD, LPFIBER_START_ROUTINE, LPVOID));
34MORDOR_RUNTIME_LINK_DECLARATION(FindFirstStreamW, HANDLE, WINAPI, (LPCWSTR, STREAM_INFO_LEVELS, LPVOID, DWORD));
35MORDOR_RUNTIME_LINK_DECLARATION(FindNextStreamW, BOOL, APIENTRY, (HANDLE, LPVOID));
36MORDOR_RUNTIME_LINK_DECLARATION(FlsAlloc, DWORD, WINAPI, (PFLS_CALLBACK_FUNCTION));
37MORDOR_RUNTIME_LINK_DECLARATION(FlsFree, BOOL, WINAPI, (DWORD));
38MORDOR_RUNTIME_LINK_DECLARATION(FlsGetValue, PVOID, WINAPI, (DWORD));
39MORDOR_RUNTIME_LINK_DECLARATION(FlsSetValue, BOOL, WINAPI, (DWORD, PVOID));
40MORDOR_RUNTIME_LINK_DECLARATION(FreeAddrInfoW, VOID, WSAAPI, (PADDRINFOW));
41MORDOR_RUNTIME_LINK_DECLARATION(GetAdaptersAddresses, ULONG, WINAPI, (ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG));
42MORDOR_RUNTIME_LINK_DECLARATION(GetAddrInfoW, INT, WSAAPI, (PCWSTR, PCWSTR, const ADDRINFOW *, PADDRINFOW *));
43MORDOR_RUNTIME_LINK_DECLARATION(GetQueuedCompletionStatusEx, BOOL, WINAPI, (HANDLE, LPOVERLAPPED_ENTRY, ULONG, PULONG, DWORD, BOOL));
44MORDOR_RUNTIME_LINK_DECLARATION(IsThreadAFiber, BOOL, WINAPI, (VOID));
45MORDOR_RUNTIME_LINK_DECLARATION(RtlCaptureStackBackTrace, WORD, NTAPI, (DWORD, DWORD, PVOID *, PDWORD));
46MORDOR_RUNTIME_LINK_DECLARATION(RtlNtStatusToDosError, ULONG, NTAPI, (NTSTATUS));
47MORDOR_RUNTIME_LINK_DECLARATION(SetFileCompletionNotificationModes, BOOL, WINAPI, (HANDLE, UCHAR));
48MORDOR_RUNTIME_LINK_DECLARATION(SymFromAddr, BOOL, __stdcall, (HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO));
49MORDOR_RUNTIME_LINK_DECLARATION(SymGetLineFromAddr64, BOOL, __stdcall, (HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64));
50MORDOR_RUNTIME_LINK_DECLARATION(WinHttpCloseHandle, BOOL, WINAPI, (HINTERNET));
51MORDOR_RUNTIME_LINK_DECLARATION(WinHttpGetDefaultProxyConfiguration, BOOL, WINAPI, (WINHTTP_PROXY_INFO *));
52MORDOR_RUNTIME_LINK_DECLARATION(WinHttpGetIEProxyConfigForCurrentUser, BOOL, WINAPI, (WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *));
53MORDOR_RUNTIME_LINK_DECLARATION(WinHttpGetProxyForUrl, BOOL, WINAPI, (HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS *, WINHTTP_PROXY_INFO *));
54MORDOR_RUNTIME_LINK_DECLARATION(WinHttpDetectAutoProxyConfigUrl, BOOL, WINAPI, (DWORD, LPWSTR *));
55MORDOR_RUNTIME_LINK_DECLARATION(WinHttpOpen, HINTERNET, WINAPI, (LPCWSTR, DWORD, LPCWSTR, LPCWSTR, DWORD));
56MORDOR_RUNTIME_LINK_DECLARATION(inet_pton, INT, WSAAPI, (INT, PCSTR, PVOID));
57}
58
59#endif