📄 dll_main.c
字号:
/****************************************************************************** Mesa 3-D graphics library* Direct3D Driver Interface** ========================================================================** Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.** Permission is hereby granted, free of charge, to any person obtaining a* copy of this software and associated documentation files (the "Software"),* to deal in the Software without restriction, including without limitation* the rights to use, copy, modify, merge, publish, distribute, sublicense,* and/or sell copies of the Software, and to permit persons to whom the* Software is furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included* in all copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL* SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE* SOFTWARE.** ======================================================================** Language: ANSI C* Environment: Windows 9x (Win32)** Description: Win32 DllMain functions.*****************************************************************************/// INITGUID must only be defined once.// Don't put it in a shared header file!// GLD3 uses dxguid.lib, so INITGUID must *not* be used!#ifndef _USE_GLD3_WGL#define INITGUID#endif // _USE_GLD3_WGL#include "dllmain.h"//#include "snap/graphics.h"//#include "drvlib/os/os.h"#ifdef _USE_GLD3_WGLtypedef void (APIENTRY *LPDGLSPLASHSCREEN)(int, int, char*);#include "gld_driver.h"#endif// ***********************************************************************BOOL bInitialized = FALSE; // callback driver initialized?BOOL bExited = FALSE; // callback driver exited this instance?HINSTANCE hInstanceDll = NULL; // DLL instance handlestatic BOOL bDriverValidated = FALSE; // prior validation statusstatic BOOL bSplashScreen = TRUE; // Splash Screen ?static BOOL bValidINIFound = FALSE; // Have we found a valid INI file?HHOOK hKeyHook = NULL; // global keyboard handler hook// Multi-threaded support needs to be reflected in Mesa code. (DaveM)int _gld_bMultiThreaded = FALSE;// ***********************************************************************DWORD dwLogging = 0; // Logging flagDWORD dwDebugLevel = 0; // Log debug levelchar szLogPath[_MAX_PATH] = {"\0"}; // Log file pathchar szSNAPPath[_MAX_PATH] = {"\0"}; // SNAP driver path#ifndef _USE_GLD3_WGLDGL_wglFuncs wglFuncs = { sizeof(DGL_wglFuncs), DGL_ChoosePixelFormat, DGL_CopyContext, DGL_CreateContext, DGL_CreateLayerContext, DGL_DeleteContext, DGL_DescribeLayerPlane, DGL_DescribePixelFormat, DGL_GetCurrentContext, DGL_GetCurrentDC, DGL_GetDefaultProcAddress, DGL_GetLayerPaletteEntries, DGL_GetPixelFormat, DGL_GetProcAddress, DGL_MakeCurrent, DGL_RealizeLayerPalette, DGL_SetLayerPaletteEntries, DGL_SetPixelFormat, DGL_ShareLists, DGL_SwapBuffers, DGL_SwapLayerBuffers, DGL_UseFontBitmapsA, DGL_UseFontBitmapsW, DGL_UseFontOutlinesA, DGL_UseFontOutlinesW,};DGL_mesaFuncs mesaFuncs = { sizeof(DGL_mesaFuncs),};#endif // _USE_GLD3_WGL// ***********************************************************************typedef struct { DWORD dwDriver; // 0=SciTech SW, 1=Direct3D SW, 2=Direct3D HW BOOL bMipmapping; // 0=off, 1=on BOOL bMultitexture; // 0=off, 1=on BOOL bWaitForRetrace; // 0=off, 1=on BOOL bFullscreenBlit; // 0=off, 1=on BOOL bFastFPU; // 0=off, 1=on BOOL bDirectDrawPersistant;// 0=off, 1=on BOOL bPersistantBuffers; // 0=off, 1=on DWORD dwLogging; // 0=off, 1=normal, 2=crash-proof DWORD dwLoggingSeverity; // 0=all, 1=warnings+errors, 2=errors only BOOL bMessageBoxWarnings;// 0=off, 1=on BOOL bMultiThreaded; // 0=off, 1=on BOOL bAppCustomizations; // 0=off, 1=on BOOL bHotKeySupport; // 0=off, 1=on BOOL bSplashScreen; // 0=off, 1=on#ifdef _USE_GLD3_WGL // // New for GLDirect 3.0 // DWORD dwAdapter; // DX8 adpater ordinal DWORD dwTnL; // Transform & Lighting type DWORD dwMultisample; // DX8 multisample type#endif // _USE_GLD3_WGL} INI_settings;static INI_settings ini;// ***********************************************************************BOOL APIENTRY DGL_initDriver(#ifdef _USE_GLD3_WGL void){#else DGL_wglFuncs *lpWglFuncs, DGL_mesaFuncs *lpMesaFuncs){ // Check for valid pointers if ((lpWglFuncs == NULL) || (lpMesaFuncs == NULL)) return FALSE; // Check for valid structs if (lpWglFuncs->dwSize != sizeof(DGL_wglFuncs)) { return FALSE; } // Check for valid structs if (lpMesaFuncs->dwSize != sizeof(DGL_mesaFuncs)) { return FALSE; } // Copy the Mesa functions memcpy(&mesaFuncs, lpMesaFuncs, sizeof(DGL_mesaFuncs)); // Pass back the wgl functions memcpy(lpWglFuncs, &wglFuncs, sizeof(DGL_wglFuncs));#endif // _USE_GLD3_WGL // Finally initialize the callback driver if (!dglInitDriver()) return FALSE; return TRUE;};// ***********************************************************************BOOL ReadINIFile( HINSTANCE hInstance){ char szModuleFilename[MAX_PATH]; char szSystemDirectory[MAX_PATH]; const char szSectionName[] = "Config"; char szINIFile[MAX_PATH]; int pos; // Now using the DLL module handle. KeithH, 24/May/2000. // Addendum: GetModuleFileName(NULL, ... returns process filename, // GetModuleFileName(hModule, ... returns DLL filename, // Get the dll path and filename. GetModuleFileName(hInstance, &szModuleFilename[0], MAX_PATH); // NULL for current process // Get the System directory. GetSystemDirectory(&szSystemDirectory[0], MAX_PATH); // Test to see if DLL is in system directory. if (strnicmp(szModuleFilename, szSystemDirectory, strlen(szSystemDirectory))==0) { // DLL *is* in system directory. // Return FALSE to indicate that registry keys should be read. return FALSE; } // Compose filename of INI file strcpy(szINIFile, szModuleFilename); pos = strlen(szINIFile); while (szINIFile[pos] != '\\') { pos--; } szINIFile[pos+1] = '\0'; // Use run-time DLL path for log file too strcpy(szLogPath, szINIFile); szLogPath[pos] = '\0'; // Complete full INI file path strcat(szINIFile, "gldirect.ini"); // Read settings from private INI file. // Note that defaults are contained in the calls. ini.dwDriver = GetPrivateProfileInt(szSectionName, "dwDriver", 2, szINIFile); ini.bMipmapping = GetPrivateProfileInt(szSectionName, "bMipmapping", 1, szINIFile); ini.bMultitexture = GetPrivateProfileInt(szSectionName, "bMultitexture", 1, szINIFile); ini.bWaitForRetrace = GetPrivateProfileInt(szSectionName, "bWaitForRetrace", 0, szINIFile); ini.bFullscreenBlit = GetPrivateProfileInt(szSectionName, "bFullscreenBlit", 0, szINIFile); ini.bFastFPU = GetPrivateProfileInt(szSectionName, "bFastFPU", 1, szINIFile); ini.bDirectDrawPersistant = GetPrivateProfileInt(szSectionName, "bPersistantDisplay", 0, szINIFile); ini.bPersistantBuffers = GetPrivateProfileInt(szSectionName, "bPersistantResources", 0, szINIFile); ini.dwLogging = GetPrivateProfileInt(szSectionName, "dwLogging", 0, szINIFile); ini.dwLoggingSeverity = GetPrivateProfileInt(szSectionName, "dwLoggingSeverity", 0, szINIFile); ini.bMessageBoxWarnings = GetPrivateProfileInt(szSectionName, "bMessageBoxWarnings", 0, szINIFile); ini.bMultiThreaded = GetPrivateProfileInt(szSectionName, "bMultiThreaded", 0, szINIFile); ini.bAppCustomizations = GetPrivateProfileInt(szSectionName, "bAppCustomizations", 1, szINIFile); ini.bHotKeySupport = GetPrivateProfileInt(szSectionName, "bHotKeySupport", 0, szINIFile); ini.bSplashScreen = GetPrivateProfileInt(szSectionName, "bSplashScreen", 1, szINIFile);#ifdef _USE_GLD3_WGL // New for GLDirect 3.x ini.dwAdapter = GetPrivateProfileInt(szSectionName, "dwAdapter", 0, szINIFile); // dwTnL now defaults to zero (chooses TnL at runtime). KeithH ini.dwTnL = GetPrivateProfileInt(szSectionName, "dwTnL", 0, szINIFile); ini.dwMultisample = GetPrivateProfileInt(szSectionName, "dwMultisample", 0, szINIFile);#endif return TRUE;}// ***********************************************************************BOOL dllReadRegistry( HINSTANCE hInstance){ // Read settings from INI file, if available bValidINIFound = FALSE; if (ReadINIFile(hInstance)) { const char *szRendering[3] = { "SciTech Software Renderer", "Direct3D MMX Software Renderer", "Direct3D Hardware Renderer" }; // Set globals glb.bPrimary = 1; glb.bHardware = (ini.dwDriver == 2) ? 1 : 0;#ifndef _USE_GLD3_WGL memset(&glb.ddGuid, 0, sizeof(glb.ddGuid)); glb.d3dGuid = (ini.dwDriver == 2) ? IID_IDirect3DHALDevice : IID_IDirect3DRGBDevice;#endif // _USE_GLD3_WGL strcpy(glb.szDDName, "Primary"); strcpy(glb.szD3DName, szRendering[ini.dwDriver]); glb.dwRendering = ini.dwDriver; glb.bUseMipmaps = ini.bMipmapping; glb.bMultitexture = ini.bMultitexture; glb.bWaitForRetrace = ini.bWaitForRetrace; glb.bFullscreenBlit = ini.bFullscreenBlit; glb.bFastFPU = ini.bFastFPU; glb.bDirectDrawPersistant = ini.bDirectDrawPersistant; glb.bPersistantBuffers = ini.bPersistantBuffers; dwLogging = ini.dwLogging; dwDebugLevel = ini.dwLoggingSeverity; glb.bMessageBoxWarnings = ini.bMessageBoxWarnings; glb.bMultiThreaded = ini.bMultiThreaded; glb.bAppCustomizations = ini.bAppCustomizations; glb.bHotKeySupport = ini.bHotKeySupport; bSplashScreen = ini.bSplashScreen;#ifdef _USE_GLD3_WGL // New for GLDirect 3.x glb.dwAdapter = ini.dwAdapter; glb.dwDriver = ini.dwDriver; glb.dwTnL = ini.dwTnL; glb.dwMultisample = ini.dwMultisample;#endif bValidINIFound = TRUE; return TRUE; } // Read settings from registry else { HKEY hReg; DWORD cbValSize; DWORD dwType = REG_SZ; // Registry data type for strings BOOL bRegistryError; BOOL bSuccess;#define REG_READ_DWORD(a, b) \ cbValSize = sizeof(b); \ if (ERROR_SUCCESS != RegQueryValueEx( hReg, (a), \ NULL, NULL, (LPBYTE)&(b), &cbValSize )) \ bRegistryError = TRUE;#define REG_READ_DEVICEID(a, b) \ cbValSize = MAX_DDDEVICEID_STRING; \ if(ERROR_SUCCESS != RegQueryValueEx(hReg, (a), 0, &dwType, \ (LPBYTE)&(b), &cbValSize)) \ bRegistryError = TRUE;#define REG_READ_STRING(a, b) \ cbValSize = sizeof((b)); \ if(ERROR_SUCCESS != RegQueryValueEx(hReg, (a), 0, &dwType, \ (LPBYTE)&(b), &cbValSize)) \ bRegistryError = TRUE; // Read settings from the registry. // Open the registry key for the current user if it exists. bSuccess = (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, DIRECTGL_REG_SETTINGS_KEY, 0, KEY_READ, &hReg)); // Otherwise open the registry key for the local machine. if (!bSuccess) bSuccess = (ERROR_SUCCESS == RegOpenKeyEx(DIRECTGL_REG_KEY_ROOT, DIRECTGL_REG_SETTINGS_KEY, 0, KEY_READ, &hReg)); if (!bSuccess) return FALSE; bRegistryError = FALSE; REG_READ_DWORD(DIRECTGL_REG_SETTING_PRIMARY, glb.bPrimary); REG_READ_DWORD(DIRECTGL_REG_SETTING_D3D_HW, glb.bHardware);#ifndef _USE_GLD3_WGL REG_READ_DWORD(DIRECTGL_REG_SETTING_DD_GUID, glb.ddGuid); REG_READ_DWORD(DIRECTGL_REG_SETTING_D3D_GUID, glb.d3dGuid);#endif // _USE_GLD3_WGL REG_READ_DWORD(DIRECTGL_REG_SETTING_LOGGING, dwLogging); REG_READ_DWORD(DIRECTGL_REG_SETTING_DEBUGLEVEL, dwDebugLevel); REG_READ_DWORD(DIRECTGL_REG_SETTING_RENDERING, glb.dwRendering); REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTITEXTURE, glb.bMultitexture); REG_READ_DWORD(DIRECTGL_REG_SETTING_WAITFORRETRACE, glb.bWaitForRetrace); REG_READ_DWORD(DIRECTGL_REG_SETTING_FULLSCREENBLIT, glb.bFullscreenBlit); REG_READ_DWORD(DIRECTGL_REG_SETTING_USEMIPMAPS, glb.bUseMipmaps); REG_READ_DEVICEID(DIRECTGL_REG_SETTING_DD_NAME, glb.szDDName); REG_READ_DEVICEID(DIRECTGL_REG_SETTING_D3D_NAME, glb.szD3DName); REG_READ_DWORD(DIRECTGL_REG_SETTING_MSGBOXWARNINGS, glb.bMessageBoxWarnings); REG_READ_DWORD(DIRECTGL_REG_SETTING_PERSISTDISPLAY, glb.bDirectDrawPersistant); REG_READ_DWORD(DIRECTGL_REG_SETTING_PERSISTBUFFERS, glb.bPersistantBuffers); REG_READ_DWORD(DIRECTGL_REG_SETTING_FASTFPU, glb.bFastFPU); REG_READ_DWORD(DIRECTGL_REG_SETTING_HOTKEYS, glb.bHotKeySupport); REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTITHREAD, glb.bMultiThreaded); REG_READ_DWORD(DIRECTGL_REG_SETTING_APPCUSTOM, glb.bAppCustomizations); REG_READ_DWORD(DIRECTGL_REG_SETTING_SPLASHSCREEN, bSplashScreen);#ifdef _USE_GLD3_WGL // New for GLDirect 3.x glb.dwDriver = glb.dwRendering; REG_READ_DWORD(DIRECTGL_REG_SETTING_ADAPTER, glb.dwAdapter); REG_READ_DWORD(DIRECTGL_REG_SETTING_TNL, glb.dwTnL); REG_READ_DWORD(DIRECTGL_REG_SETTING_MULTISAMPLE, glb.dwMultisample);#endif RegCloseKey(hReg); // Open the global registry key for GLDirect bSuccess = (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, DIRECTGL_REG_SETTINGS_KEY, 0, KEY_READ, &hReg)); if (bSuccess) { // Read the installation path for GLDirect REG_READ_STRING("InstallLocation",szLogPath); RegCloseKey(hReg); } if (bRegistryError || !bSuccess) return FALSE; else return TRUE;#undef REG_READ_DWORD#undef REG_READ_DEVICEID#undef REG_READ_STRING }}// ***********************************************************************BOOL dllWriteRegistry( void ){ HKEY hReg; DWORD dwCreateDisposition, cbValSize; BOOL bRegistryError = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -