Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185/* vfdlib.c
Virtual Floppy Drive for Windows Driver control library Miscellaneous functions
Copyright (C) 2003-2008 Ken Kato*/
#ifdef __cplusplus#pragma message(__FILE__": Compiled as C++ for testing purpose.")#endif // __cplusplus
#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <stdio.h>
#ifdef _DEBUG#include <psapi.h>#endif // _DEBUG
#include "vfdtypes.h"#include "vfdapi.h"#include "vfdlib.h"
//// DLL Global variables//
#ifndef __REACTOS__extern HINSTANCE g_hDllModule = NULL; // Handle to this DLL itselfextern UINT g_cDllRefCnt = 0; // Reference count of this DLLextern UINT g_nNotifyMsg = 0; // VFD notification message#elseHINSTANCE g_hDllModule = NULL; // Handle to this DLL itselfUINT g_cDllRefCnt = 0; // Reference count of this DLLUINT g_nNotifyMsg = 0; // VFD notification message#endif
//// DllMain//BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved){#ifdef _DEBUG char name[MAX_PATH]; HMODULE hMod; DWORD size;
if (EnumProcessModules(GetCurrentProcess(), &hMod, sizeof(hMod), &size)) { GetModuleBaseName(GetCurrentProcess(), hMod, name, sizeof(name)); } else { strcpy(name, "unknown"); }#endif // _DEBUG
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH) { VFDTRACE(0, ("DLL_PROCESS_ATTACH - %s\n", name));
// this DLL doesn't need DLL_THREAD_ATTACH and DLL_THREAD_DETACH DisableThreadLibraryCalls(hInstance);
// store the DLL instance handle g_hDllModule = hInstance;
// register the VFD notification message g_nNotifyMsg = RegisterWindowMessage(VFD_NOTIFY_MESSAGE);
} else if (dwReason == DLL_PROCESS_DETACH) { VFDTRACE(0, ("DLL_PROCESS_DETACH - %s\n", name)); }
return TRUE;}
//// Check running platform//BOOL WINAPI VfdIsValidPlatform(){ BOOL (WINAPI *pfnIsWow64Process)(HANDLE, PBOOL); BOOL wow64;
if (GetVersion() & 0x80000000) { return FALSE; // doesn't work on Win9x }
pfnIsWow64Process = (BOOL (WINAPI *)(HANDLE, PBOOL)) GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
if (pfnIsWow64Process == NULL) { return TRUE; // NT4 or 2000 -- assured to be 32 bit }
wow64 = FALSE;
if (!pfnIsWow64Process(GetCurrentProcess(), &wow64)) { return FALSE; }
return !wow64;}
//// Get VFD notification message value//UINT WINAPI VfdGetNotifyMessage(){ return g_nNotifyMsg;}
//// Get message text from this DLL module//PSTR ModuleMessage( DWORD nFormat, ...){ PSTR p; va_list args;
va_start(args, nFormat);
if (!FormatMessage( FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER, g_hDllModule, nFormat, 0, (LPTSTR)&p, 0, &args)) { p = NULL; }
va_end(args);
return p;}
//// Get system error message string//PCSTR SystemMessage( DWORD nError){ static CHAR msg[256];
if (!FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, nError, 0, msg, sizeof(msg), NULL)) {
_snprintf(msg, sizeof(msg), "Unknown system error %lu (0x%08x)\n", nError, nError); }
return msg;}
#ifdef _DEBUG//// Format and output debug string//void DebugTrace( PCSTR sFormat, ...){ CHAR buf[512]; int len; va_list args;
len = _snprintf(buf, sizeof(buf), "%s(%lu) : ", TraceFile, TraceLine);
va_start(args, sFormat);
_vsnprintf(buf + len, sizeof(buf) - len, sFormat, args);
OutputDebugString(buf);}#endif // _DEBUG