ReactOS  0.4.14-dev-358-gbef841c
vfdlib.c
Go to the documentation of this file.
1 /*
2  vfdlib.c
3 
4  Virtual Floppy Drive for Windows
5  Driver control library
6  Miscellaneous functions
7 
8  Copyright (C) 2003-2008 Ken Kato
9 */
10 
11 #ifdef __cplusplus
12 #pragma message(__FILE__": Compiled as C++ for testing purpose.")
13 #endif // __cplusplus
14 
15 #define WIN32_LEAN_AND_MEAN
16 #include <windows.h>
17 #include <stdio.h>
18 
19 #ifdef _DEBUG
20 #include <psapi.h>
21 #endif // _DEBUG
22 
23 #include "vfdtypes.h"
24 #include "vfdapi.h"
25 #include "vfdlib.h"
26 
27 //
28 // DLL Global variables
29 //
30 
31 #ifndef __REACTOS__
32 extern HINSTANCE g_hDllModule = NULL; // Handle to this DLL itself
33 extern UINT g_cDllRefCnt = 0; // Reference count of this DLL
34 extern UINT g_nNotifyMsg = 0; // VFD notification message
35 #else
36 HINSTANCE g_hDllModule = NULL; // Handle to this DLL itself
37 UINT g_cDllRefCnt = 0; // Reference count of this DLL
38 UINT g_nNotifyMsg = 0; // VFD notification message
39 #endif
40 
41 //
42 // DllMain
43 //
47  LPVOID lpReserved)
48 {
49 #ifdef _DEBUG
50  char name[MAX_PATH];
51  HMODULE hMod;
52  DWORD size;
53 
54  if (EnumProcessModules(GetCurrentProcess(), &hMod, sizeof(hMod), &size)) {
55  GetModuleBaseName(GetCurrentProcess(), hMod, name, sizeof(name));
56  }
57  else {
58  strcpy(name, "unknown");
59  }
60 #endif // _DEBUG
61 
62  UNREFERENCED_PARAMETER(lpReserved);
63 
65  VFDTRACE(0, ("DLL_PROCESS_ATTACH - %s\n", name));
66 
67  // this DLL doesn't need DLL_THREAD_ATTACH and DLL_THREAD_DETACH
69 
70  // store the DLL instance handle
72 
73  // register the VFD notification message
75 
76  }
77  else if (dwReason == DLL_PROCESS_DETACH) {
78  VFDTRACE(0, ("DLL_PROCESS_DETACH - %s\n", name));
79  }
80 
81  return TRUE;
82 }
83 
84 //
85 // Check running platform
86 //
88 {
89  BOOL (WINAPI *pfnIsWow64Process)(HANDLE, PBOOL);
90  BOOL wow64;
91 
92  if (GetVersion() & 0x80000000) {
93  return FALSE; // doesn't work on Win9x
94  }
95 
96  pfnIsWow64Process = (BOOL (WINAPI *)(HANDLE, PBOOL))
97  GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
98 
99  if (pfnIsWow64Process == NULL) {
100  return TRUE; // NT4 or 2000 -- assured to be 32 bit
101  }
102 
103  wow64 = FALSE;
104 
105  if (!pfnIsWow64Process(GetCurrentProcess(), &wow64)) {
106  return FALSE;
107  }
108 
109  return !wow64;
110 }
111 
112 //
113 // Get VFD notification message value
114 //
116 {
117  return g_nNotifyMsg;
118 }
119 
120 
121 //
122 // Get message text from this DLL module
123 //
125  DWORD nFormat, ...)
126 {
127  PSTR p;
128  va_list args;
129 
130  va_start(args, nFormat);
131 
132  if (!FormatMessage(
135  g_hDllModule, nFormat, 0, (LPTSTR)&p, 0, &args)) {
136  p = NULL;
137  }
138 
139  va_end(args);
140 
141  return p;
142 }
143 
144 //
145 // Get system error message string
146 //
148  DWORD nError)
149 {
150  static CHAR msg[256];
151 
152  if (!FormatMessage(
155  NULL, nError, 0, msg, sizeof(msg), NULL)) {
156 
157  _snprintf(msg, sizeof(msg),
158  "Unknown system error %lu (0x%08x)\n", nError, nError);
159  }
160 
161  return msg;
162 }
163 
164 #ifdef _DEBUG
165 //
166 // Format and output debug string
167 //
168 void DebugTrace(
169  PCSTR sFormat, ...)
170 {
171  CHAR buf[512];
172  int len;
173  va_list args;
174 
175  len = _snprintf(buf, sizeof(buf),
176  "%s(%lu) : ", TraceFile, TraceLine);
177 
178  va_start(args, sFormat);
179 
180  _vsnprintf(buf + len, sizeof(buf) - len, sFormat, args);
181 
183 }
184 #endif // _DEBUG
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
#define TRUE
Definition: types.h:120
UINT g_cDllRefCnt
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
char CHAR
Definition: xmlstorage.h:175
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define OutputDebugString
Definition: winbase.h:3714
#define BOOL
Definition: nt_native.h:43
Definition: match.c:390
CHAR * LPTSTR
Definition: xmlstorage.h:192
DWORD WINAPI GetVersion(VOID)
Definition: version.c:22
static BOOL wow64
Definition: psapi_main.c:49
DWORD dwReason
Definition: misc.cpp:154
#define _snprintf
Definition: xmlstorage.h:200
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI VfdIsValidPlatform()
Definition: vfdlib.c:87
char * va_list
Definition: acmsvcex.h:78
#define VFD_NOTIFY_MESSAGE
Definition: vfdlib.h:48
BOOL * PBOOL
Definition: windef.h:161
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: vfdlib.c:44
#define DLL_PROCESS_DETACH
Definition: compat.h:119
GLsizeiptr size
Definition: glext.h:5919
BOOL WINAPI EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
Definition: psapi.c:542
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
HINSTANCE g_hDllModule
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
UINT WINAPI VfdGetNotifyMessage()
Definition: vfdlib.c:115
#define FormatMessage
Definition: winbase.h:3619
GLenum GLsizei len
Definition: glext.h:6722
#define RegisterWindowMessage
Definition: winuser.h:5741
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
#define GetModuleBaseName
Definition: psapi.h:132
#define GetModuleHandle
Definition: winbase.h:3651
UINT g_nNotifyMsg
signed char * PSTR
Definition: retypes.h:7
#define va_start(ap, A)
Definition: acmsvcex.h:91
unsigned int UINT
Definition: ndis.h:50
#define _vsnprintf
Definition: xmlstorage.h:202
#define msg(x)
Definition: auth_time.c:54
Definition: name.c:36
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define GetProcAddress(x, y)
Definition: compat.h:418
const char * PCSTR
Definition: typedefs.h:51
GLfloat GLfloat p
Definition: glext.h:8902
#define args
Definition: format.c:66