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

📄 tmmanins.c

📁 PNX系列设备驱动 PNX系列设备驱动
💻 C
字号:
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <io.h>
#include <stdlib.h>
#include <sys\stat.h>

#define constVendorID	"VEN_1131"
#define constDeviceID   "DEV_5400"

void DeleteOldFiles(void);
void RemoveOldDevices(void);
void InstallDriver(void);
    
int WINAPI WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
                    LPSTR lpCmdLine, int nCmdShow)
{   
   	OSVERSIONINFO		OSVersion;

	OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx( &OSVersion );
	if(OSVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)
	{
		MessageBox(NULL,"This program cannot run on Windows NT","tmmanins.exe",MB_OK | MB_ICONSTOP);
		return 1;
	}
	if(MessageBox(NULL,"Warning: This program will delete the existing\n" 
		               "TriMedia device and associated drivers.\n\n"
				  	   "Do you want to continue?\n",
		"tmmanins.exe",MB_ICONQUESTION | MB_YESNO) == IDYES)
	{
		DeleteOldFiles();
		RemoveOldDevices();
		InstallDriver();
		return 0;
	}
	else
		return 1;
}

void RemoveOldDevices(void)
{
	HKEY	RegistryHandle;
	HKEY	RegistryHandle2;
	DWORD	BytesXfered;
	char    subKey[200];
	char	tempStr[200];
	char	driver[100];
	FILETIME   fileTime; 
	DWORD	index=0;
	static  char	delEntries[32][200];
	DWORD	delEntriesCount;
	char    infPath[200];

    BytesXfered = sizeof (subKey);
	// initialize default values
	if ( ERROR_SUCCESS == RegOpenKeyEx(  
		HKEY_LOCAL_MACHINE,
		"Enum\\PCI\\",
		0,
		KEY_READ,
		&RegistryHandle ) )
	{
		delEntriesCount=0;
		while(1)
		{
		    BytesXfered = sizeof (subKey);
			if(RegEnumKeyEx(RegistryHandle,index,subKey,&BytesXfered,NULL,NULL,NULL,&fileTime) == ERROR_NO_MORE_ITEMS)
				break;
			index++;
			strupr(subKey);
	    	if(strstr(subKey,constVendorID) != NULL 
	    		&& strstr(subKey,constDeviceID)  != NULL)
			{
				sprintf(tempStr,"Enum\\PCI\\%s",subKey);
				strcpy(delEntries[delEntriesCount],tempStr);
				delEntriesCount++;
			}
		}
		RegCloseKey(RegistryHandle);
	}

	for(index=0;index < delEntriesCount; index++)
		RegDeleteKey(HKEY_LOCAL_MACHINE, delEntries[index]);


	if ( ERROR_SUCCESS == RegOpenKeyEx(  
		HKEY_LOCAL_MACHINE,
		"System\\CurrentControlSet\\Services\\Class\\Media",
		0,
		KEY_READ,
		&RegistryHandle ) )
	{
		delEntriesCount=0;
		index=0;
		while(1)
		{
		    BytesXfered = sizeof (subKey);
			if(RegEnumKeyEx(RegistryHandle,index,subKey,&BytesXfered,NULL,NULL,NULL,&fileTime) == ERROR_NO_MORE_ITEMS)
				break;
			BytesXfered=sizeof(driver);
			index++;
			sprintf(tempStr,"System\\CurrentControlSet\\Services\\Class\\Media\\%s",subKey);
			if ( ERROR_SUCCESS == RegOpenKeyEx(  
				HKEY_LOCAL_MACHINE,
				tempStr,
				0,
				KEY_READ,
				&RegistryHandle2 ) )
			{
			    BytesXfered = sizeof (driver);
				if ( ERROR_SUCCESS == RegQueryValueEx(
					RegistryHandle2,
					TEXT("Driver"),
					NULL,
					NULL,
					(BYTE*)&driver,
					&BytesXfered ) )
				{
					if(strcmpi(driver,"tmman.vxd") == 0 || 
					   strcmpi(driver,"vtmman.vxd") == 0)
					{
						strcpy(delEntries[delEntriesCount],tempStr);
						delEntriesCount++;
						// Remove INF file
						BytesXfered = sizeof (infPath);
						if ( ERROR_SUCCESS == RegQueryValueEx(
							RegistryHandle2,
							TEXT("InfPath"),
							NULL,
							NULL,
							(BYTE*)&infPath,
							&BytesXfered ) )
						{
							GetWindowsDirectory(tempStr,sizeof(tempStr));
							strcat(tempStr,"\\inf\\other\\");
							strcat(tempStr,infPath);
							unlink(tempStr);
						}
					}
				}
				else			// Win98 WDM Driver
				{
					BytesXfered = sizeof (driver);
					if ( ERROR_SUCCESS == RegQueryValueEx(
						RegistryHandle2,
						TEXT("NTMPDriver"),
						NULL,
						NULL,
						(BYTE*)&driver,
						&BytesXfered ) )
					{
						if(strcmpi(driver,"tmman.sys") == 0)
						{
							strcpy(delEntries[delEntriesCount],tempStr);
							delEntriesCount++;
							// Remove INF file
							BytesXfered = sizeof (infPath);
							if ( ERROR_SUCCESS == RegQueryValueEx(
								RegistryHandle2,
								TEXT("InfPath"),
								NULL,
								NULL,
								(BYTE*)&infPath,
								&BytesXfered ) )
							{
								GetWindowsDirectory(tempStr,sizeof(tempStr));
								strcat(tempStr,"\\inf\\other\\");
								strcat(tempStr,infPath);
								unlink(tempStr);
							}
						}
					}
				}

				RegCloseKey(RegistryHandle2);
			}
		}
		RegCloseKey(RegistryHandle);
	}

	for(index=0;index < delEntriesCount; index++)
		RegDeleteKey(HKEY_LOCAL_MACHINE, delEntries[index]);
		

/*
    RemoveDeviceMedia();;
    RemoveDeviceOther();
	*/
}
	
// Delete old VXD and DLL from Windows System directory
void DeleteOldFiles(void)
{
	WORD wReturn;
	int i;
	char szBuf[_MAX_PATH];
	char fileBuf[_MAX_PATH];
	char *filesToDelete[]={"vtmman.vxd","tmman.vxd","tmman32.dll","tmcrt.dll",
						"authhost.dll","tmcons.exe","tmrun.exe","tmmprun.exe"};
		
	wReturn = GetSystemDirectory((LPSTR) szBuf, sizeof(szBuf));
	 
	if (wReturn != 0)
	{
		for(i=0;i<sizeof(filesToDelete)/sizeof(char *);i++)
		{                                        
			sprintf(fileBuf,"%s\\%s",szBuf,filesToDelete[i]);
			if(access(fileBuf,0) == 0)		/* File Exists */
			{
				chmod(fileBuf,_S_IREAD | _S_IWRITE);
				unlink(fileBuf);
			}
		}  
// Delete Win98 WDM driver		
		sprintf(fileBuf,"%s32\\drivers\\tmman.sys",szBuf);
		if(access(fileBuf,0) == 0)		/* File Exists */
		{
			chmod(fileBuf,_S_IREAD | _S_IWRITE);
			unlink(fileBuf);
		}
	}
}

void InstallDriver(void)
{
    MessageBeep(-1);
	MessageBox(NULL,"Driver removal successfully done.\n\n"
		            "To complete the driver installation,\n"
					"reboot and when Windows asks for a driver location,\n"
					"specify the directory Windows\\Data\\drivers\\Win9x on CD containing tmman9x.inf.\n\n"
					"Click OK","Important",MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
#if 0		
	DEVICE_INFO di;
	DRIVER_NODE dn;
	int i;	        
	char szBuf[80];
	ATOM atom;
	RETERR ret;

	di.cbSize=sizeof(DEVICE_INFO);
	di.lpNextDi=NULL;
	di.hRegKey=HKEY_LOCAL_MACHINE;
	strcpy(di.szClassName,"Media");
	
	dn.InfType=INFTYPE_TEXT;
	strcpy(dn.lpszDrvDescription,"TriMedia IREF Board");
	strcpy(dn.lpszHardwareID,"PCI\\VEN_1131&DEV_5400");
	atom=GlobalAddAtom("q:\\v2.0\\build\\win95\\bin\\win95\\tmman.inf");
	if (atom != 0)
	{
		dn.atInfFileName=atom;
		di.lpSelectedDriver=&dn;
		ret=DiInstallDevice(&di);
		if(ret == OK)
		{
		}
	}
#endif	
}

⌨️ 快捷键说明

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