FreeTDS API: win32/initnet.c Source File

FreeTDS API

Loading...
Searching...
No Matches
initnet.c
1#include <config.h>
2
3#if defined(_MSC_VER) && defined(_DEBUG)
4#define _CRTDBG_MAP_ALLOC
5#include <stdlib.h>
6#include <crtdbg.h>
7#endif
8
9#include <freetds/windows.h>
10#include <freetds/macros.h>
11#include <freetds/sysdep_private.h>
12#include <freetds/utils/path.h>
13
14#ifdef DLL_EXPORT
15
16HINSTANCE hinstFreeTDS;
17
18#if defined(_MSC_VER) && defined(_DEBUG)
19static HANDLE crt_file = _CRTDBG_FILE_STDOUT;
20#endif
21
22BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
23
24BOOL WINAPI
25DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved TDS_UNUSED)
26{
27#if defined(_MSC_VER) && defined(_DEBUG)
28 const tds_dir_char *crt_filename;
29#endif
30
31 hinstFreeTDS = hinstDLL;
32 switch (fdwReason) {
33 case DLL_PROCESS_ATTACH:
34#if defined(_MSC_VER) && defined(_DEBUG)
35 crt_filename = tds_dir_getenv(TDS_DIR("TDS_DEBUG_CRT_FILENAME"));
36 if (crt_filename) {
37 HANDLE file =
38 CreateFileW(crt_filename, GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, CREATE_ALWAYS,
39 FILE_ATTRIBUTE_NORMAL, NULL);
40
41 if (file != INVALID_HANDLE_VALUE)
42 crt_file = file;
43 }
44
45 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
46 _CrtSetReportFile(_CRT_WARN, crt_file);
47 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
48 _CrtSetReportFile(_CRT_ERROR, crt_file);
49 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
50 _CrtSetReportFile(_CRT_ASSERT, crt_file);
51 _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
52#endif
53
54 if (tds_socket_init() != 0)
55 return FALSE;
56
57 DisableThreadLibraryCalls(hinstDLL);
58 break;
59
60 case DLL_PROCESS_DETACH:
61 tds_socket_done();
62#if defined(_MSC_VER) && defined(_DEBUG)
63 _CrtDumpMemoryLeaks();
64 if (crt_file != _CRTDBG_FILE_STDOUT) {
65 CloseHandle(crt_file);
66 crt_file = _CRTDBG_FILE_STDOUT;
67 }
68#endif
69 break;
70 }
71 return TRUE;
72}
73
74#endif