ReactOS 0.4.16-dev-250-g3ecd236
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__
32extern HINSTANCE g_hDllModule = NULL; // Handle to this DLL itself
33extern UINT g_cDllRefCnt = 0; // Reference count of this DLL
34extern UINT g_nNotifyMsg = 0; // VFD notification message
35#else
36HINSTANCE g_hDllModule = NULL; // Handle to this DLL itself
37UINT g_cDllRefCnt = 0; // Reference count of this DLL
38UINT 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)) {
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;
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//
168void DebugTrace(
169 PCSTR sFormat, ...)
170{
171 CHAR buf[512];
172 int len;
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
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define msg(x)
Definition: auth_time.c:54
DWORD dwReason
Definition: misc.cpp:141
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define GetProcAddress(x, y)
Definition: compat.h:753
#define GetCurrentProcess()
Definition: compat.h:759
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOL WINAPI EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
Definition: psapi.c:526
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define GetModuleBaseName
Definition: psapi.h:132
static BOOL wow64
Definition: psapi_main.c:44
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define args
Definition: format.c:66
Definition: match.c:390
Definition: name.c:39
char * PSTR
Definition: typedefs.h:51
PVOID HANDLE
Definition: typedefs.h:73
const char * PCSTR
Definition: typedefs.h:52
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
UINT g_cDllRefCnt
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
HINSTANCE g_hDllModule
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
UINT g_nNotifyMsg
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: vfdlib.c:44
BOOL WINAPI VfdIsValidPlatform()
Definition: vfdlib.c:87
UINT WINAPI VfdGetNotifyMessage()
Definition: vfdlib.c:115
#define VFD_NOTIFY_MESSAGE
Definition: vfdlib.h:48
#define FormatMessage
Definition: winbase.h:3820
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:446
#define GetModuleHandle
Definition: winbase.h:3852
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:445
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:448
#define OutputDebugString
Definition: winbase.h:3915
BOOL * PBOOL
Definition: windef.h:161
#define WINAPI
Definition: msvc.h:6
#define RegisterWindowMessage
Definition: winuser.h:5852
#define _vsnprintf
Definition: xmlstorage.h:202
#define _snprintf
Definition: xmlstorage.h:200
CHAR * LPTSTR
Definition: xmlstorage.h:192
char CHAR
Definition: xmlstorage.h:175