/* * Copyright (c) 2003 Andy Polyakov * * Build with: * * cl -Ox -GD -GF -Zl -MD -LD lptone.c user32.lib kernel32.lib ntdll.lib * * Pre-load as: * * [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DLL_PRELOAD] * "SERVICES.EXE"="lptone.dll" * * See http://fy.chalmers.se/~appro/nt/DLL_PRELOAD/ for further details. * */ #ifndef _DLL #error "_DLL is not defined." #endif #pragma comment(linker,"/entry:DllMain@12") #pragma comment(linker,"/section:.text,erw") #pragma comment(linker,"/merge:.rdata=.text") #pragma comment(linker,"/merge:.data=.text") #if defined(WIN32) && !defined(_WIN32) #define _WIN32 #endif #define _WIN32_WINNT 0x0500 #include #include #include #if defined(UNICODE) || defined(_UNICODE) #define _snprintf _snwprintf #endif #define PORT _T("LPT1") #define DEVICE _T("\\Device\\Null") BOOL WINAPI DllMain (HINSTANCE h, DWORD reason, LPVOID junk) { TCHAR out[256]; MSGBOXPARAMS m; LPVOID lpMsgBuf; while (reason==DLL_PROCESS_ATTACH) { DisableThreadLibraryCalls(h); if (QueryDosDevice(PORT,out,sizeof(out)/sizeof(TCHAR))) break; else if (GetLastError() != ERROR_FILE_NOT_FOUND) break; if (DefineDosDevice(DDD_RAW_TARGET_PATH,PORT,DEVICE) == 0) { FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, // Default language (LPTSTR) &lpMsgBuf, 0, NULL); _snprintf (out,sizeof(out)/sizeof(TCHAR)-1, _T("DefineDosDevice(\"%s\",\"%s\") failed: %s"), PORT,DEVICE,lpMsgBuf); out[sizeof(out)/sizeof(TCHAR)-1]=_T('\0'); LocalFree(lpMsgBuf); m.cbSize = sizeof(m); m.hwndOwner = NULL; m.lpszCaption = _T("LPTONE Failure Notice"); m.dwStyle = MB_OK; m.hInstance = NULL; m.lpszIcon = IDI_ERROR; m.dwContextHelpId = 0; m.lpfnMsgBoxCallback= NULL; m.dwLanguageId = MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US); m.lpszText = out; MessageBoxIndirect(&m); } break; } return TRUE; }