Watt-32 tcp/ip  2.2 dev-rel.10
win_dll.h
Go to the documentation of this file.
1 
5 #ifndef _w32_WIN_DLL_H
6 #define _w32_WIN_DLL_H
7 
8 #if defined(WIN32)
9 
10 #include <tchar.h>
11 
12 /* Generic table for loading DLLs and functions from them.
13  */
14 struct LoadTable {
15  HINSTANCE mod_handle;
16  const TCHAR *mod_name;
17  const char *func_name;
18  void **func_addr;
19  };
20 
21 extern struct LoadTable dyn_funcs[];
22 extern size_t dyn_funcs_num;
23 
24 extern int load_dynamic_table (struct LoadTable *tab, int tab_size);
25 extern int unload_dynamic_table (struct LoadTable *tab, int tab_size);
26 
27 #if defined(UNICODE) || defined(_UNICODE)
28  #define TSTR2ASCII_FMT WIDESTR_FMT
29 #else
30  #define TSTR2ASCII_FMT "s"
31 #endif
32 
33 #ifndef IN
34 #define IN
35 #endif
36 
37 #ifndef OUT
38 #define OUT
39 #endif
40 
41 #ifndef OPTIONAL
42 #define OPTIONAL
43 #endif
44 
45 /*
46  * Instead of including <NtDDK.h> here, we define undocumented stuff
47  * needed for NtQueryInformationThread() here:
48  */
49 typedef LONG NTSTATUS;
50 
51 typedef enum _THREADINFOCLASS {
52  ThreadBasicInformation,
53  ThreadTimes,
54  ThreadPriority,
55  ThreadBasePriority,
56  ThreadAffinityMask,
57  ThreadImpersonationToken,
58  ThreadDescriptorTableEntry,
59  ThreadEnableAlignmentFaultFixup,
60  ThreadEventPair_Reusable,
61  ThreadQuerySetWin32StartAddress,
62  ThreadZeroTlsCell,
63  ThreadPerformanceCount,
64  ThreadAmILastThread,
65  ThreadIdealProcessor,
66  ThreadPriorityBoost,
67  ThreadSetTlsArrayAddress,
68  ThreadIsIoPending,
69  MaxThreadInfoClass
70  } THREADINFOCLASS;
71 
72 /* end <NTddk.h> stuff */
73 
74 /*
75  * All function typedefs and function pointers are declared below
76  * so that load_dynamic_table() can see the function pointers.
77  */
78 
79 typedef BOOL (WINAPI *func_QueryThreadCycleTime) (
80  IN HANDLE thread_handle,
81  OUT ULONG64 *cycle_time);
82 
83 typedef NTSTATUS (WINAPI *func_NtQueryInformationThread) (
84  IN HANDLE thread_handle,
85  IN THREADINFOCLASS thread_information_class,
86  IN OUT void *thread_information,
87  IN ULONG thread_information_length,
88  OUT ULONG *return_length OPTIONAL);
89 
90 typedef DWORD (WINAPI *func_GetFileVersionInfoSizeA) (char *, DWORD*);
91 typedef BOOL (WINAPI *func_GetFileVersionInfoA) (char *, DWORD, DWORD, void *);
92 typedef BOOL (WINAPI *func_VerQueryValueA) (const void **, char *, void **, UINT *);
93 typedef BOOL (WINAPI *func_GetComputerNameExA) (int, char*, DWORD*);
94 typedef BOOL (WINAPI *func_IsWow64Process) (HANDLE, BOOL*);
95 
96 extern func_GetFileVersionInfoSizeA p_GetFileVersionInfoSizeA;
97 extern func_GetFileVersionInfoA p_GetFileVersionInfoA;
98 extern func_VerQueryValueA p_VerQueryValueA;
99 extern func_QueryThreadCycleTime p_QueryThreadCycleTime;
100 extern func_NtQueryInformationThread p_NtQueryInformationThread;
101 extern func_GetComputerNameExA p_GetComputerNameExA;
102 extern func_IsWow64Process p_IsWow64Process;
103 
104 #if defined(HAVE_WINDNS_H)
105  /*
106  * DnsApi.dll is used dynamically. So we need the function pointers below.
107  * <windns.h> should be part of the "Platform SDK".
108  */
109  #include <windns.h>
110 
111  typedef DNS_STATUS (WINAPI *func_DnsQuery_A) (
112  IN const char *name,
113  IN WORD wType,
114  IN DWORD options,
115  IN IP4_ARRAY *aipServers,
116  IN OUT DNS_RECORD **queryResults,
117  IN OUT void **reserved);
118 
119  typedef DNS_STATUS (WINAPI *func_DnsModifyRecordsInSet_A) (
120  IN DNS_RECORD *addRecords,
121  IN DNS_RECORD *deleteRecords,
122  IN DWORD options,
123  IN HANDLE context, OPTIONAL
124  IN IP4_ARRAY *serverList, OPTIONAL
125  IN void *reserved);
126 
127  typedef void (WINAPI *func_DnsFree) (
128  IN OUT void *data,
129  IN DNS_FREE_TYPE freeType);
130 
131  extern func_DnsFree p_DnsFree;
132  extern func_DnsQuery_A p_DnsQuery_A;
133  extern func_DnsModifyRecordsInSet_A p_DnsModifyRecordsInSet_A;
134 #endif
135 
136 #if 1
137  #include "packet32.h"
138 #else
139  typedef void WAN_ADAPTER; /* The details of this struct is not important to us.
140  * Ref. WAN_ADAPTER_INT in WanPacket.cpp (from CACE Technologies)
141  */
142  struct bpf_stat; /* Forward. Defined in packet32.h */
143 #endif
144 
145 /* "func_": WanPacket-function typedefs.
146  * These are *not* WINAPI.
147  */
148 typedef BOOL (*func_WanPacketSetBpfFilter) (WAN_ADAPTER *, PUCHAR, DWORD);
149 typedef WAN_ADAPTER *(*func_WanPacketOpenAdapter) (void);
150 typedef BOOL (*func_WanPacketCloseAdapter) (WAN_ADAPTER *);
151 typedef BOOL (*func_WanPacketSetBufferSize)(WAN_ADAPTER *, DWORD);
152 typedef DWORD (*func_WanPacketReceivePacket) (WAN_ADAPTER *, PUCHAR, DWORD);
153 typedef BOOL (*func_WanPacketSetMinToCopy) (WAN_ADAPTER *, DWORD);
154 typedef BOOL (*func_WanPacketGetStats) (WAN_ADAPTER *, struct bpf_stat *);
155 typedef BOOL (*func_WanPacketSetReadTimeout) (WAN_ADAPTER *, DWORD);
156 typedef BOOL (*func_WanPacketSetMode) (WAN_ADAPTER *, DWORD);
157 typedef HANDLE (*func_WanPacketGetReadEvent) (WAN_ADAPTER *);
158 typedef BOOL (*func_WanPacketTestAdapter) (void);
159 
160 extern func_WanPacketSetBpfFilter p_WanPacketSetBpfFilter;
161 extern func_WanPacketOpenAdapter p_WanPacketOpenAdapter;
162 extern func_WanPacketCloseAdapter p_WanPacketCloseAdapter;
163 extern func_WanPacketSetBufferSize p_WanPacketSetBufferSize;
164 extern func_WanPacketReceivePacket p_WanPacketReceivePacket;
165 extern func_WanPacketSetMinToCopy p_WanPacketSetMinToCopy;
166 extern func_WanPacketGetStats p_WanPacketGetStats;
167 extern func_WanPacketSetReadTimeout p_WanPacketSetReadTimeout;
168 extern func_WanPacketSetMode p_WanPacketSetMode;
169 extern func_WanPacketGetReadEvent p_WanPacketGetReadEvent;
170 extern func_WanPacketTestAdapter p_WanPacketTestAdapter;
171 
172 #if defined(USE_BUGTRAP)
173  /*
174  * Dynamically load the BugTrap DLL.
175  * Ref: http://www.intellesoft.net/default.shtml
176  */
177  #include "bugtrap.h"
178 
179  #define EXC_FUN LPTOP_LEVEL_EXCEPTION_FILTER
180 
181  typedef EXC_FUN (APIENTRY *func_BT_InstallSehFilter) (void);
182  typedef void (APIENTRY *func_BT_SetPreErrHandler) (BT_ErrHandler, INT_PTR);
183  typedef void (APIENTRY *func_BT_SetAppVersion) (const char *appVersion);
184  typedef void (APIENTRY *func_BT_SetAppName) (const char *appName);
185  typedef void (APIENTRY *func_BT_SetReportFormat) (BUGTRAP_REPORTFORMAT format);
186  typedef void (APIENTRY *func_BT_SetSupportEMail) (const char *supportEmail);
187  typedef INT_PTR (APIENTRY *func_BT_OpenLogFile) (const char *logFileName, BUGTRAP_LOGFORMAT logFormat);
188  typedef void (APIENTRY *func_BT_SetFlags) (DWORD dwFlags);
189  typedef BOOL (APIENTRY *func_BT_SetLogSizeInEntries) (INT_PTR handle, DWORD logSizeInEntries);
190  typedef BOOL (APIENTRY *func_BT_SetLogFlags) (INT_PTR handle, DWORD flags);
191  typedef BOOL (APIENTRY *func_BT_SetLogEchoMode) (INT_PTR handle, DWORD logEchoMode);
192  typedef BOOL (APIENTRY *func_BT_InsLogEntryF) (INT_PTR handle, BUGTRAP_LOGLEVEL logLevel, LPCTSTR format, ...);
193  typedef BOOL (APIENTRY *func_BT_CloseLogFile) (INT_PTR handle);
194  typedef void (APIENTRY *func_BT_AddLogFile) (const char *logFile);
195 
196  extern func_BT_InstallSehFilter p_BT_InstallSehFilter;
197  extern func_BT_SetPreErrHandler p_BT_SetPreErrHandler;
198  extern func_BT_SetAppVersion p_BT_SetAppVersion;
199  extern func_BT_SetAppName p_BT_SetAppName;
200  extern func_BT_SetReportFormat p_BT_SetReportFormat;
201  extern func_BT_SetSupportEMail p_BT_SetSupportEMail;
202  extern func_BT_SetFlags p_BT_SetFlags;
203  extern func_BT_SetLogSizeInEntries p_BT_SetLogSizeInEntries;
204  extern func_BT_SetLogFlags p_BT_SetLogFlags;
205  extern func_BT_SetLogEchoMode p_BT_SetLogEchoMode;
206  extern func_BT_InsLogEntryF p_BT_InsLogEntryF;
207  extern func_BT_OpenLogFile p_BT_OpenLogFile;
208  extern func_BT_CloseLogFile p_BT_CloseLogFile;
209  extern func_BT_AddLogFile p_BT_AddLogFile;
210 
211 #endif /* USE_BUGTRAP */
212 #endif /* WIN32 */
213 #endif /* _w32_WIN_DLL_H */
214