⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dll_main.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:

#define REG_WRITE_DWORD(a, b)							\
	cbValSize = sizeof(b);								\
	if (ERROR_SUCCESS != RegSetValueEx( hReg, (a),		\
		0, REG_DWORD, (LPBYTE)&(b), cbValSize ))		\
		bRegistryError = TRUE;

	if (ERROR_SUCCESS == RegCreateKeyEx( DIRECTGL_REG_KEY_ROOT, DIRECTGL_REG_SETTINGS_KEY,
										0, NULL, 0, KEY_WRITE, NULL, &hReg,
										&dwCreateDisposition )) {
		RegFlushKey(hReg); // Make sure keys are written to disk
		RegCloseKey(hReg);
		hReg = NULL;
		}

	if (bRegistryError)
		return FALSE;
	else
		return TRUE;

#undef REG_WRITE_DWORD
}

// ***********************************************************************

void dglInitHotKeys(HINSTANCE hInstance)
{
	// Hot-Key support at all?
	if (!glb.bHotKeySupport)
		return;

	// Install global keyboard interceptor
	hKeyHook = SetWindowsHookEx(WH_KEYBOARD, dglKeyProc, hInstance, 0);
}

// ***********************************************************************

void dglExitHotKeys(void)
{
	// Hot-Key support at all?
	if (!glb.bHotKeySupport)
		return;

	// Remove global keyboard interceptor
	if (hKeyHook)
		UnhookWindowsHookEx(hKeyHook);
	hKeyHook = NULL;
}

// ***********************************************************************

// Note: This app-customization step must be performed in both the main
// OpenGL32 driver and the callback driver DLLs for multithreading option.
void dglSetAppCustomizations(void)
{
	char		szModuleFileName[MAX_PATH];
	int			iSize = MAX_PATH;

	// Get the currently loaded EXE filename.
	GetModuleFileName(NULL, &szModuleFileName[0], MAX_PATH); // NULL for current process
	strupr(szModuleFileName);
	iSize = strlen(szModuleFileName);

	// Check for specific EXEs and adjust global settings accordingly

	// NOTE: In GLD3.x "bDirectDrawPersistant" corresponds to IDirect3D8 and
	//       "bPersistantBuffers" corresponds to IDirect3DDevice8. KeithH

	// Case 1: 3DStudio must be multi-threaded
	// Added: Discreet GMAX (3DStudio MAX 4 for gamers. KeithH)
	if (strstr(szModuleFileName, "3DSMAX.EXE")
		|| strstr(szModuleFileName, "3DSVIZ.EXE")
		|| strstr(szModuleFileName, "GMAX.EXE")) {
		glb.bMultiThreaded = TRUE;
		glb.bDirectDrawPersistant = FALSE;
		glb.bPersistantBuffers = FALSE;
		return;
	}

	// Case 2: Solid Edge must use pre-allocated resources for all GLRCs
	if (strstr(szModuleFileName, "PART.EXE")
		|| strstr(szModuleFileName, "ASSEMBL.EXE")
		|| strstr(szModuleFileName, "DRAFT.EXE")
		|| strstr(szModuleFileName, "SMARTVW.EXE")
		|| strstr(szModuleFileName, "SMETAL.EXE")) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = TRUE;
		glb.bPersistantBuffers = FALSE;
		return;
	}

	// Case 3: Sudden Depth creates and destroys GLRCs on paint commands
	if (strstr(szModuleFileName, "SUDDEPTH.EXE")
		|| strstr(szModuleFileName, "SUDDEMO.EXE")) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = TRUE;
		glb.bPersistantBuffers = TRUE;
		glb.bFullscreenBlit = TRUE;
		return;
	}

	// Case 4: StereoGraphics test apps create and destroy GLRCs on paint commands
	if (strstr(szModuleFileName, "REDBLUE.EXE")
		|| strstr(szModuleFileName, "DIAGNOSE.EXE")) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = TRUE;
		glb.bPersistantBuffers = TRUE;
		return;
	}

	// Case 5: Pipes screen savers share multiple GLRCs for same window
	if (strstr(szModuleFileName, "PIPES.SCR")
		|| (strstr(szModuleFileName, "PIPES") && strstr(szModuleFileName, ".SCR"))) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = TRUE;
		glb.bPersistantBuffers = TRUE;
		return;
	}

	// Case 6: AutoVue uses sub-viewport ops which are temporarily broken in stereo window
	if (strstr(szModuleFileName, "AVWIN.EXE")) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = TRUE;
		glb.bPersistantBuffers = TRUE;
		return;
	}
	// Case 7: Quake3 is waiting for DDraw objects to be released at exit
	if (strstr(szModuleFileName, "QUAKE")) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = FALSE;
		glb.bPersistantBuffers = FALSE;
        glb.bFullscreenBlit = FALSE;
		return;
	}
	// Case 8: Reflection GLX server is unable to switch contexts at run-time
	if (strstr(szModuleFileName, "RX.EXE")) {
		glb.bMultiThreaded = FALSE;
        glb.bMessageBoxWarnings = FALSE;
		return;
	}
	// Case 9: Original AutoCAD 2000 must share DDraw objects across GLRCs
	if (strstr(szModuleFileName, "ACAD.EXE")) {
		glb.bFastFPU = FALSE;
        if (GetModuleHandle("wopengl6.hdi") != NULL) {
		glb.bMultiThreaded = FALSE;
		glb.bDirectDrawPersistant = TRUE;
		glb.bPersistantBuffers = FALSE;
		}
		return;
	}
}

// ***********************************************************************

BOOL dglInitDriver(void)
{
	UCHAR szExeName[MAX_PATH];
	const char *szRendering[] = {
		"Mesa Software",
		"Direct3D RGB SW",
		"Direct3D HW",
	};
    static BOOL bWarnOnce = FALSE;

    // Already initialized?
    if (bInitialized)
        return TRUE;

    // Moved from DllMain DLL_PROCESS_ATTACH:

		// (Re-)Init defaults
		dglInitGlobals();

		// Read registry or INI file settings
		if (!dllReadRegistry(hInstanceDll)) {
            if (!bWarnOnce)
			    MessageBox( NULL, "GLDirect has not been configured.\n\n"
							  "Please run the configuration program\n"
                              "before using GLDirect with applications.\n",
							  "GLDirect", MB_OK | MB_ICONWARNING);
            bWarnOnce = TRUE;
            return FALSE;
		}

#ifdef _USE_GLD3_WGL
		// Must do this as early as possible.
		// Need to read regkeys/ini-file first though.
		gldInitDriverPointers(glb.dwDriver);

		// Create private driver globals
		_gldDriver.CreatePrivateGlobals();
#endif
		// Overide settings with application customizations
		if (glb.bAppCustomizations)
			dglSetAppCustomizations();

//#ifndef _USE_GLD3_WGL
		// Set the global memory type to either sysmem or vidmem
		glb.dwMemoryType = glb.bHardware ? DDSCAPS_VIDEOMEMORY : DDSCAPS_SYSTEMMEMORY;
//#endif

		// Multi-threaded support overides persistant display support
		if (glb.bMultiThreaded)
			glb.bDirectDrawPersistant = glb.bPersistantBuffers = FALSE;

        // Multi-threaded support needs to be reflected in Mesa code. (DaveM)
        _gld_bMultiThreaded = glb.bMultiThreaded;

		// Start logging
        ddlogPathOption(szLogPath);
		ddlogWarnOption(glb.bMessageBoxWarnings);
		ddlogOpen((DDLOG_loggingMethodType)dwLogging,
				  (DDLOG_severityType)dwDebugLevel);

		// Obtain the name of the calling app
		ddlogMessage(DDLOG_SYSTEM, "Driver           : SciTech GLDirect 4.0\n");
		GetModuleFileName(NULL, szExeName, sizeof(szExeName));
		ddlogPrintf(DDLOG_SYSTEM, "Executable       : %s", szExeName);

		ddlogPrintf(DDLOG_SYSTEM, "DirectDraw device: %s", glb.szDDName);
		ddlogPrintf(DDLOG_SYSTEM, "Direct3D driver  : %s", glb.szD3DName);

		ddlogPrintf(DDLOG_SYSTEM, "Rendering type   : %s", szRendering[glb.dwRendering]);

		ddlogPrintf(DDLOG_SYSTEM, "Multithreaded    : %s", glb.bMultiThreaded ? "Enabled" : "Disabled");
		ddlogPrintf(DDLOG_SYSTEM, "Display resources: %s", glb.bDirectDrawPersistant ? "Persistant" : "Instanced");
		ddlogPrintf(DDLOG_SYSTEM, "Buffer resources : %s", glb.bPersistantBuffers ? "Persistant" : "Instanced");

		dglInitContextState();
		dglBuildPixelFormatList();
		//dglBuildTextureFormatList();

    // D3D callback driver is now successfully initialized
    bInitialized = TRUE;
    // D3D callback driver is now ready to be exited
    bExited = FALSE;

    return TRUE;
}

// ***********************************************************************

void dglExitDriver(void)
{

	// Only need to clean up once per instance:
	// May be called implicitly from DLL_PROCESS_DETACH,
	// or explicitly from DGL_exitDriver().
	if (bExited)
		return;
	bExited = TRUE;

    // DDraw objects may be invalid when DLL unloads.
__try {

	// Clean-up sequence (moved from DLL_PROCESS_DETACH)
#ifndef _USE_GLD3_WGL
	dglReleaseTextureFormatList();
#endif
	dglReleasePixelFormatList();
	dglDeleteContextState();

#ifdef _USE_GLD3_WGL
	_gldDriver.DestroyPrivateGlobals();
#endif

}
__except(EXCEPTION_EXECUTE_HANDLER) {
	    ddlogPrintf(DDLOG_WARN, "Exception raised in dglExitDriver.");
}

	// Close the log file
	ddlogClose();
}

// ***********************************************************************

int WINAPI DllMain(
	HINSTANCE hInstance,
	DWORD fdwReason,
	PVOID pvReserved)
{
	switch (fdwReason) {
	case DLL_PROCESS_ATTACH:
        // Cache DLL instance handle
        hInstanceDll = hInstance;

        // Flag that callback driver has yet to be initialized
        bInitialized = bExited = FALSE;

#ifndef _USE_GLD3_WGL
        // Init internal Mesa function pointers
		memset(&mesaFuncs, 0, sizeof(DGL_mesaFuncs));
#endif // _USE_GLD3_WGL

		// Init defaults
		dglInitGlobals();

        // Defer rest of DLL initialization to 1st WGL function call
		break;

	case DLL_PROCESS_DETACH:
		// Call exit clean-up sequence
		dglExitDriver();
		break;
	}

	return TRUE;
}

// ***********************************************************************

void APIENTRY DGL_exitDriver(void)
{
	// Call exit clean-up sequence
	dglExitDriver();
}

// ***********************************************************************

void APIENTRY DGL_reinitDriver(void)
{
	// Force init sequence again
    bInitialized = bExited = FALSE;
	dglInitDriver();
}

// ***********************************************************************

int WINAPI DllInitialize(
	HINSTANCE hInstance,
	DWORD fdwReason,
	PVOID pvReserved)
{
	// Some Watcom compiled executables require this.
	return DllMain(hInstance, fdwReason, pvReserved);
}

// ***********************************************************************

void DGL_LoadSplashScreen(int piReg, char* pszUser)
{
	HINSTANCE			hSplashDll = NULL;
	LPDGLSPLASHSCREEN 	dglSplashScreen = NULL;
	static BOOL 		bOnce = FALSE;
    static int          iReg = 0;
    static char         szUser[255] = {"\0"};

    // Display splash screen at all?
    if (!bSplashScreen)
        return;

	// Only display splash screen once
	if (bOnce)
		return;
	bOnce = TRUE;

    // Make local copy of string for passing to DLL
    if (pszUser)
        strcpy(szUser, pszUser);
    iReg = piReg;

	// Load Splash Screen DLL
	// (If it fails to load for any reason, we don't care...)
	hSplashDll = LoadLibrary("gldsplash.dll");
	if (hSplashDll) {
		// Execute the Splash Screen function
		dglSplashScreen = (LPDGLSPLASHSCREEN)GetProcAddress(hSplashDll, "GLDSplashScreen");
		if (dglSplashScreen)
			(*dglSplashScreen)(1, iReg, szUser);
		// Don't unload the DLL since splash screen dialog is modeless now
		}
}

// ***********************************************************************

BOOL dglValidate()
{
	char *szCaption = "SciTech GLDirect Driver";
	UINT uType = MB_OK | MB_ICONEXCLAMATION;

#ifdef _USE_GLD3_WGL
	// (Re)build pixelformat list
	if (glb.bPixelformatsDirty)
		_gldDriver.BuildPixelformatList();
#endif

	// Check to see if we have already validated
	if (bDriverValidated && bInitialized)
		return TRUE;

    // Since all (most) the WGL functions must be validated at this point,
    // this also insure that the callback driver is completely initialized.
    if (!bInitialized)
        if (!dglInitDriver()) {
			MessageBox(NULL,
				"The GLDirect driver could not initialize.\n\n"
				"Please run the configuration program to\n"
				"properly configure the driver, or else\n"
                "re-run the installation program.", szCaption, uType);
			_exit(1); // Bail
        }

    return TRUE;
}

// ***********************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -