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

📄 embocheck2.cpp

📁 1,wince下做的导入注册表的程序.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	memset(buffer, 0, sizeof buffer);
	mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szDUpdatesServerPass, MAX_LEN_16); 
	if(buffer[0]==NULL)
	{
		memset(buffer, 0, sizeof buffer);  
		mbstowcs((LPTSTR)buffer,(LPSTR)pEmboBaseInfo_In->szNCServerPass, MAX_LEN_16);  
	}
	wcscpy(pnetwork->Password, buffer);
	dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
	if(ERROR_SUCCESS==dwRegResult)
	{
		dwRegValueLength=MAX_PATH;
		dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerPassword"),0,&dwRegValueType,NULL,&dwRegValueLength); 
		if(ERROR_SUCCESS==dwRegResult)
		{
			dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesServerPassword"),0,&dwRegValueType,(LPBYTE)pnetwork->Password, &dwRegValueLength);
		}
		RegCloseKey(hKey);
	}
}
void CloseAllEvents()
{
	if(NULL!=	hEmbo_Folder_Ready_Event)
	CloseHandle(hEmbo_Folder_Ready_Event);

	if(NULL!=	hEmbo_FileCopy_Ready_Event)
	CloseHandle(hEmbo_FileCopy_Ready_Event);

	if(NULL!=	hEmbo_Registry_Ready_Event)
	CloseHandle(hEmbo_Registry_Ready_Event);

	if(NULL!=	hEmbo_AutoRun_Ready_Event)
	CloseHandle(hEmbo_AutoRun_Ready_Event);

}

BOOL CreateAllEvents()
{
#define Embo_Folder_Ready_Event		_T("Embo_Folder_Ready_Event") 
	hEmbo_Folder_Ready_Event=CreateEvent(NULL, TRUE, FALSE, Embo_Folder_Ready_Event); // Manual reset
	if(NULL==hEmbo_Folder_Ready_Event)
	{
		ERRORMSG(1,(_T("Failed to create hEmbo_Folder_Ready_Event: (0x%X)\r\n"),GetLastError()));
		goto ERROR_RETURN2;
	}

#define Embo_FileCopy_Ready_Event	_T("Embo_FileCopy_Ready_Event") 
	hEmbo_FileCopy_Ready_Event=CreateEvent(NULL, TRUE, FALSE, Embo_FileCopy_Ready_Event); // Manual reset
	if(NULL==hEmbo_FileCopy_Ready_Event)
	{
		ERRORMSG(1,(_T("Failed to create hEmbo_FileCopy_Ready_Event: (0x%X)\r\n"),GetLastError()));
		goto ERROR_RETURN2;
	}

#define Embo_Registry_Ready_Event	_T("Embo_Registry_Ready_Event") 
	hEmbo_Registry_Ready_Event=CreateEvent(NULL, TRUE, FALSE, Embo_Registry_Ready_Event); // Manual reset
	if(NULL==hEmbo_Registry_Ready_Event)
	{
		ERRORMSG(1,(_T("Failed to create hEmbo_Registry_Ready_Event: (0x%X)\r\n"),GetLastError()));
		goto ERROR_RETURN2;
	}

#define Embo_AutoRun_Ready_Event	_T("Embo_AutoRun_Ready_Event") 
	hEmbo_AutoRun_Ready_Event=CreateEvent(NULL, TRUE, FALSE, Embo_AutoRun_Ready_Event); // Manual reset
	if(NULL==hEmbo_AutoRun_Ready_Event)
	{
		ERRORMSG(1,(_T("Failed to create hEmbo_AutoRun_Ready_Event: (0x%X)\r\n"),GetLastError()));
		goto ERROR_RETURN2;
	}
	return TRUE;

ERROR_RETURN2:
//	CloseAllEvents();
	return FALSE;
}

DWORD WorkingThread( LPVOID lpParameter )
{
	TCHAR *pcsPath=NULL;
	DWORD dwStatus=TRUE;
	TCHAR csPath[MAX_PATH]={0};
	BOOL fRetValue=FALSE;	        
	//Create All Events
	dwStatus=CreateAllEvents();
	if(FALSE==dwStatus) goto ERROR_RETURN;

//(0)	//从 emboloader 取baseinfo
	dwStatus=GetBaseinfoFromLoader(&g_bootArg, &g_baseInfo);
	if(FALSE==dwStatus) goto ERROR_RETURN;

//(1)	//取 g_IsPureOS 从g_baseInfo, default = FALSE ///////////////////////////////////
	g_IsPureOS=g_baseInfo.dwIsPureOS;
	//再从注册表取
	dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
	if(ERROR_SUCCESS==dwRegResult)
	{
		dwRegValueLength=MAX_PATH;
		dwRegResult=RegQueryValueEx(hKey,TEXT("IsPureOS"),0,&dwRegValueType,NULL,&dwRegValueLength); 
		if(ERROR_SUCCESS==dwRegResult)
		{
			dwRegResult=RegQueryValueEx(hKey,TEXT("IsPureOS"),0,&dwRegValueType,(LPBYTE)&g_IsPureOS,&dwRegValueLength);
		}
		RegCloseKey(hKey);
	}
	//保存g_IsPureOS 到registry, 按REG_OPTION_VOLATILE模式
  	if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK,
						0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
	{
		if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("IsPureOS"), 
 					0, REG_DWORD, (const BYTE *)&g_IsPureOS, sizeof(DWORD) ))
		{
			DEBUGMSG(1,(_T("Error: Can not write g_IsPureOS to Registry!")));
		}
		RegCloseKey(hKey);
	}
	//如果g_IsPureOS!=0,直接退出
	if(g_IsPureOS!=0)
	{
		goto ERROR_RETURN;
	}
	
//(2)	//取 g_IsNetwork 从g_baseInfo, default = FALSE ///////////////////////////////////
	g_IsNetwork=g_baseInfo.dwDUpdatesIsNetwork;
	//再从注册表取
	dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
	if(ERROR_SUCCESS==dwRegResult)
	{
		dwRegValueLength=MAX_PATH;
		dwRegResult=RegQueryValueEx(hKey,TEXT("IsNetwork"),0,&dwRegValueType,NULL,&dwRegValueLength); 
		if(ERROR_SUCCESS==dwRegResult)
		{
			dwRegResult=RegQueryValueEx(hKey,TEXT("IsNetwork"),0,&dwRegValueType,(LPBYTE)&g_IsNetwork,&dwRegValueLength);
		}
		RegCloseKey(hKey);
	}

//(3)	//取 g_szEmboRoot, default = _T("harddisk") ///////////////////////////////////
	_tcscpy(g_szEmboRoot, _T("\\harddisk"));
	//如果g_baseInfo.szDUpatesRoot非空,则g_szEmboRoot用之
	if(NULL!=*g_baseInfo.szDUpdatesRoot)
	{
		mbstowcs((LPTSTR)g_szEmboRoot,(LPSTR)g_baseInfo.szDUpdatesRoot, MAX_LEN_64);
	}
	//否则用g_baseInfo.szCurrentPath
	else 
	{
		mbstowcs((LPTSTR)g_szEmboRoot,(LPSTR)g_baseInfo.szCurrentPath, MAX_PATH);
	}
	//再看注册表是否有DUpdatesRoot
	dwRegResult=RegOpenKeyEx(HKEY_LOCAL_MACHINE,REG_KEY_EMBO_DUPDATES,0,0,&hKey);
	if(ERROR_SUCCESS==dwRegResult)
	{
		dwRegValueLength=MAX_PATH;
		dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesRoot"),0,&dwRegValueType,NULL,&dwRegValueLength); 
		if(ERROR_SUCCESS==dwRegResult)
		{
			dwRegResult=RegQueryValueEx(hKey,TEXT("DUpdatesRoot"),0,&dwRegValueType,(LPBYTE)&g_szEmboRoot,&dwRegValueLength);
		}
		RegCloseKey(hKey);
	}
	//得到g_szEmboRoot,现在开始整理格式:
	if((*g_szEmboRoot==NULL) || (!(_tcsicmp(g_szEmboRoot, _T("\\")))))		//如果路径为空或者是根"\",直接退出。
	{
		goto ERROR_RETURN;
	}
	//如果路径首字节不为'\',转换为'\'。
	_tcscpy(csPath, g_szEmboRoot);
	if(*csPath!=_T('\\'))	
	{
		_stprintf(g_szEmboRoot, _T("\\%s"), csPath);
	}
	//如果路径尾字节为'\',删除'\'。
	if(g_szEmboRoot[_tcslen(g_szEmboRoot)-1]==_T('\\'))	
	{
		g_szEmboRoot[_tcslen(g_szEmboRoot)-1]=NULL;
	}

	_tcslwr(g_szEmboRoot);		//至此g_szEmboRoot成为(lower case)小写的 \network\???, 或者\harddisk\???

	//生成 EmboRootVolume:
	_tcscpy(csPath, g_szEmboRoot);
	pcsPath=_tcsstr(&csPath[1], _T("\\"));		//从'\'后一个字节开始再找'\'
	if(NULL!=pcsPath)
	{
		*pcsPath=NULL;
	}
	_tcscpy(g_szEmboRootVolume, csPath);	//g_szEmboRootVolume格式为小写的 \harddisk, 或者\harddisk2 等等
	
	
	//从registry 取dwWaitForLocalPathTime, dwNetworkMappingRetry, dwNetworkMappingRetryGap
	GetRegistrySettings();


	///////////////////////////////////
	//启动两个 查找线程之一
	//如果是 Network 启动 DetectNetworkPathThread
	if((TRUE==IfEmboRootIsNetwork(g_szEmboRoot)) || (g_IsNetwork))
	{
		hDetectNetworkPathThread=CreateThread( NULL, 0, DetectNetworkPathThread, 0, 0, NULL );

		if(hDetectNetworkPathThread==NULL)
		{
			ERRORMSG(1,(_T("Failed to create DetectNetworkPathThread: (0x%X)\r\n"),GetLastError()));
			goto ERROR_RETURN; //not path should find, return directly 
		}
		dwNetworkPri=GetThreadPriority(hDetectNetworkPathThread);
//		fRetValue=SetThreadPriority(hDetectNetworkPathThread, 8);

	}
	//如果是 Local 启动 DetectLocalPathThread
	else //if(TRUE==IfEmboRootIsLocal(g_szEmboRoot)) 
	{
		hDetectLocalPathThreadStopEvent=CreateEvent( NULL, FALSE, FALSE, Embo_DetectLocalPathThreadStopEvent);
		if(hDetectLocalPathThreadStopEvent==NULL)
		{
			ERRORMSG(1,(_T("Failed to create DetectLocalPathThreadStopEvent: (0x%X)\r\n"),GetLastError()));
		}
		hDetectLocalPathThread=CreateThread( NULL, 0, DetectLocalPathThread, 0, 0, NULL );
		if(hDetectLocalPathThread==NULL)
		{
			ERRORMSG(1,(_T("Failed to create DetectLocalPathThread: (0x%X)\r\n"),GetLastError()));
			goto ERROR_RETURN; //not path should find, return directly 
		}
		dwLocalPri=GetThreadPriority(hDetectLocalPathThread);
//		fRetValue=SetThreadPriority(hDetectLocalPathThread, 8);

	}

	dwStatus=WaitForPathOKEvent(dwWaitForPathOKTime);
	if(TRUE==dwStatus)
	{
  		if(ERROR_SUCCESS == RegCreateKeyEx(
							HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK,
							0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
		{
			if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("PathOK"), 
 						0, REG_DWORD, (const BYTE *)&fPathOK, sizeof(DWORD) ))
			{
				dwStatus = 0;
			}
			RegCloseKey(hKey);
		}
	
		if(FindFolders())
		{
			fFilesOK=TRUE;
		}
		if(ERROR_SUCCESS == RegCreateKeyEx(
							HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK,
							0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
		{
			if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("FilesOK"), 
 						0, REG_DWORD, (const BYTE *)&fFilesOK, sizeof(DWORD) ))
			{
				dwStatus = 0;
			}
			RegCloseKey(hKey);
		}
			
		SetFileCopyEvent();	//即使不成功也 set FileCopyEvent, 但注册表里fFilesOK=FALSE
	
	}
////////////////////////to test a driver
	/*
#define REG_KEY_EMBO_CHECK_Test_Driver _T("Drivers\\BuiltIn\\TestEmboCheck")
	DWORD dwTestDriverOrder=0x20;
	DWORD dwTestDriverIndex=0x7;
	DWORD dwTestDriverFlags=0x8;
	TCHAR TestDriverDll[]=_T("TestEmboCheck.dll");
;	TCHAR TestDriverPrefix[]=_T("TestEmboCheck.dll");
	if(ERROR_SUCCESS == RegCreateKeyEx(
							HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK_Test_Driver,
							0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
		{
			if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("Order"), 
 						0, REG_DWORD, (const BYTE *)&dwTestDriverOrder, sizeof(DWORD) ))
			{
				dwStatus = 0;
			}
			RegCloseKey(hKey);
		}

	if(ERROR_SUCCESS == RegCreateKeyEx(
							HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK_Test_Driver,
							0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
		{
			if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("Index"), 
 						0, REG_DWORD, (const BYTE *)&dwTestDriverIndex, sizeof(DWORD) ))
			{
				dwStatus = 0;
			}
			RegCloseKey(hKey);
		}
	if(ERROR_SUCCESS == RegCreateKeyEx(
							HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK_Test_Driver,
							0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
		{
			if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("Flags"), 
 						0, REG_DWORD, (const BYTE *)&dwTestDriverFlags, sizeof(DWORD) ))
			{
				dwStatus = 0;
			}
			RegCloseKey(hKey);
		}

	if(ERROR_SUCCESS == RegCreateKeyEx(
							HKEY_LOCAL_MACHINE, REG_KEY_EMBO_CHECK_Test_Driver,
							0, _T(""), REG_OPTION_VOLATILE,
							0, NULL, 
							&hKey, &dwDisposition ))
		{
			if(ERROR_SUCCESS != RegSetValueEx(hKey, TEXT("Dll"), 
 						0, REG_SZ, (const BYTE *)TestDriverDll, sizeof(TCHAR)*_tcslen(TestDriverDll) ))
			{
				dwStatus = 0;
			}
			RegCloseKey(hKey);
		}
//		dwStatus = CopyFile(_T("\\network\\test\\embobsp\\wcopy\\Auto\\Windows\\TestEmboCheck.dll"),_T("\\Windows\\TestEmboCheck.dll"),FALSE);	//总是覆盖 3rd Para is FALSE
*/
////////////////////////to test a driver
	//return TRUE;
ERROR_RETURN:
	SetAllEvents();
	//TCHAR aa[2][MAX_PATH]={0};//_T("aa"),_T("/a:\\embo-notebookxp\test2\EmboSerial1234.reg")};  
//	_tmain2 (_T("\\network\\test2\\EmboSerial1234.reg"));
//	CloseAllEvents();
	return TRUE;
}

extern "C" 
{

    __declspec(dllexport) DWORD Init(const TCHAR*)
    {
		BOOL fHandles=TRUE;
		HANDLE hCurThrd=GetCurrentThread();
		dwInitPri=GetThreadPriority(hCurThrd);
		//Create working thread
		hWorkingThread=CreateThread( NULL, 0, WorkingThread, 0, 0, NULL );
		if(hWorkingThread==NULL)
		{
			ERRORMSG(1,(_T("Failed to create WorkingThread: (0x%X)\r\n"),GetLastError()));
			fHandles=FALSE;
		}
		dwWorkingPri=GetThreadPriority(hWorkingThread);
//		fHandles=SetThreadPriority(hWorkingThread, 8);

		//Create working thread's stop event
		hWorkingThreadStopEvent=CreateEvent( NULL, FALSE, FALSE, EmboCheck_WorkingThreadStopEvent );
		if(hWorkingThreadStopEvent==NULL)
		{
			ERRORMSG(1,(_T("Failed to create WorkingThreadStopEvent: (0x%X)\r\n"),GetLastError()));
			fHandles=FALSE;
		}

		if(fHandles==TRUE)
		{
			//WaitForSingleObject(hWorkingThread, INFINITE);
			int ddd=0;
		}			
		return TRUE;
    }

    __declspec(dllexport) BOOL Deinit()
    {
		//Should test in PB, if the following will be called by device manager?
		if(hWorkingThread!=NULL)
			CloseHandle(hWorkingThread);

		if(hWorkingThreadStopEvent!=NULL)
			CloseHandle(hWorkingThreadStopEvent);

        return TRUE;
    }                  
}

/*
int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
 	// TODO: Place code here.
	DWORD dwTest=Init(_T("me"));

	return 9;
}

*/

⌨️ 快捷键说明

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