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

📄 simplelap.cpp

📁 一个嵌入式系统的生物识别的MS通用接口LAP源码
💻 CPP
字号:
// SimpleLAP.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "SimpleLAP.h"
#include <windows.h>
#include <commctrl.h>

// Inlcude the header files needed for LAP definitions.
#include <lap.h>

// dialog resources
#include "resource.h"

// Globals and functions in this module
HINSTANCE g_hInstance;
BOOL CALLBACK Enrole_DlgProc( HWND	hDlg, UINT	uMsg, WPARAM	wParam, LPARAM	lParam );
BOOL CALLBACK Verify_DlgProc( HWND	hDlg, UINT	uMsg, WPARAM	wParam, LPARAM	lParam );

// System Password functions used in this module
extern "C" {
BOOL SetPassword( LPWSTR lpszOldPassword, LPWSTR lpszNewPassword );
BOOL SetPasswordActive( BOOL bActive, LPWSTR lpszPassword );
BOOL GetPasswordActive();
BOOL CheckPassword(LPWSTR lpszPassword);
}

void WriteDebugMsg(LPTSTR Message)
{
#ifdef TRACELOG
	DWORD written = 0;
	HANDLE hFile = CreateFile(L"\\Debug.txt",GENERIC_WRITE,0,NULL,OPEN_ALWAYS,NULL,NULL);
	SetFilePointer(hFile,0,0,FILE_END);
	WriteFile(hFile, Message,wcslen(Message)*sizeof(TCHAR),&written,NULL);
	WriteFile(hFile, L"\r\n",4,&written,NULL);

	CloseHandle(hFile);
#endif // TRACELOG
}


BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	g_hInstance = (HINSTANCE)hModule;
    return TRUE;
}


////////////////////////////////////////////
//
// All Laps have init/de-init code.
//
////////////////////////////////////////////
// Sent to a LAP when it is activated.
// Return false and the LAP will not be loaded.
//   
BOOL InitLAP(
        InitLap* il
        )
{
	WriteDebugMsg(L"InitLAP");
    return TRUE; 
}


// Set to a LAP when it is being unloaded.
void DeinitLAP()
{
	WriteDebugMsg(L"DeinitLAP");
    return;
}

BOOL VerifyUser(const GUID *AEKey, /* Authenication Event Identifier */
                LPCWSTR pwszAEDisplayText, /*Text Plugin will display, if null use from registry.*/
                HWND   hwndParent, /*Parent Window if Available-else use desktop window*/
                DWORD dwOptions,
                PVOID pExtended /*Reserved, must be 0*/
                )
{
	WriteDebugMsg(L"VerifyUser");
	return DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_VERIFY_SQUARE), hwndParent, 
		Verify_DlgProc, (LPARAM)false );
}


BOOL LAPCreateEnrollmentConfigDialog(HWND hwndParent,DWORD dwOptions)
{
	WriteDebugMsg(L"LAPCreateEnrollmentConfigDialog");
	DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_ENROLE_SQUARE), hwndParent, 
		Enrole_DlgProc, (LPARAM)false );
	return true;
}


BOOL CALLBACK Enrole_DlgProc( 
	HWND	hDlg, 
	UINT	uMsg, 
	WPARAM	wParam, 
	LPARAM	lParam )
{
	switch( uMsg )
	{
		case WM_INITDIALOG:
		{
			SHINITDLGINFO shidi;
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
			SetForegroundWindow( hDlg );

			SHSetNavBarText( hDlg, TEXT("Password") );

			//
			// Enable the additional elements for updating the password.
			//
			if ( !GetPasswordActive() )
			{
				//
				// If no password is active, turn off Dissable button and old password
				//
				EnableWindow(GetDlgItem(hDlg,IDC_DISSABLE), FALSE);
				EnableWindow(GetDlgItem(hDlg,IDC_PASSWORDSTRINGOLD), FALSE);

				SetDlgItemText(hDlg,IDC_ENABLE,L"Enable");
				EnableWindow(GetDlgItem(hDlg,IDC_ENABLE), TRUE);
				EnableWindow(GetDlgItem(hDlg,IDC_PASSWORDSTRINGNEW), TRUE);
				SetDlgItemText(hDlg,IDC_PASSWORDSTRINGOLD,L"");
				SetDlgItemText(hDlg,IDC_PASSWORDSTRINGNEW,L"");
				SetFocus(GetDlgItem(hDlg,IDC_PASSWORDSTRINGNEW));
			}
			else
			{
				//
				// Password is active - allow dissable button and accept old password
				//
				SetDlgItemText(hDlg,IDC_ENABLE,L"Change");
				EnableWindow(GetDlgItem(hDlg,IDC_DISSABLE), TRUE);
				EnableWindow(GetDlgItem(hDlg,IDC_ENABLE), TRUE);
				EnableWindow(GetDlgItem(hDlg,IDC_PASSWORDSTRINGOLD), TRUE);
				EnableWindow(GetDlgItem(hDlg,IDC_PASSWORDSTRINGNEW), TRUE);
				SetDlgItemText(hDlg,IDC_PASSWORDSTRINGOLD,L"");
				SetDlgItemText(hDlg,IDC_PASSWORDSTRINGNEW,L"");
				SetFocus(GetDlgItem(hDlg,IDC_PASSWORDSTRINGOLD));
			}
		}
			return FALSE;

		case WM_CLOSE:
			EndDialog( hDlg, 0 );
			return FALSE;

		case WM_COMMAND:
			switch( LOWORD(wParam) )
			{
				case IDC_ENABLE:
					{
						// Get the old and new password values
						wchar_t OldPwd[MAX_PATH];
						wchar_t NewPwd[MAX_PATH];
						GetDlgItemText(hDlg,IDC_PASSWORDSTRINGOLD,OldPwd,MAX_PATH);
						GetDlgItemText(hDlg,IDC_PASSWORDSTRINGNEW,NewPwd,MAX_PATH);

						// Is a password active? Check with OS
						if (GetPasswordActive())
						{
							// Now check the old password is OK with the system
							if (CheckPassword(OldPwd))
							{
								// Change password values
								if (!SetPassword( OldPwd,  NewPwd))
								{
									MessageBox(hDlg, L"Failed to change the password, unknown error", L"Error",MB_OK);
								}
								else
								{
									HKEY hkey;
									//
									// Enable power-on dialog.
									//
									RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("ControlPanel\\Owner"), 0, 0, 0, 0, 0, &hkey, 0 );
									RegSetValueEx( hkey, TEXT("PowrPass"), 0, REG_BINARY, (CONST BYTE*)"\x01", 1 );
									RegCloseKey( hkey );
								}
								EndDialog( hDlg, 1 );
							}
							else
							{
								MessageBox(hDlg,L"Invalid Password - please enter Old Password",L"Error",MB_OK|MB_ICONHAND);
							}
						}
						else
						{
							// Enable for the first time - set OS password to new value
							if (!SetPassword( NULL, NewPwd))
								MessageBox(hDlg, L"Failed to set the password, unknown error", L"Error",MB_OK);
							else
								if (!SetPasswordActive( TRUE,  NewPwd )) // Now make it active
									MessageBox(hDlg, L"Failed to activate password, unknown error", L"Error",MB_OK);
								else
									{
										HKEY hkey;
										//
										// Enable power-on dialog.
										//
										RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("ControlPanel\\Owner"), 0, 0, 0, 0, 0, &hkey, 0 );
										RegSetValueEx( hkey, TEXT("PowrPass"), 0, REG_BINARY, (CONST BYTE*)"\x01", 1 );
										RegCloseKey( hkey );
									}
							EndDialog( hDlg, 1 );
						}
					}
					break;

				case IDC_DISSABLE:
					{
						// Check the OLD password value and dissable the security
						wchar_t ItemText[MAX_PATH];
						GetDlgItemText(hDlg,IDC_PASSWORDSTRINGOLD,ItemText,MAX_PATH);

						// Check the OLD password is correct
						if (CheckPassword(ItemText))
						{
							// Turn it off
							if (!SetPasswordActive(FALSE,ItemText))
								MessageBox(hDlg, L"Failed to deactivate password, unknown error", L"Error",MB_OK);
							else
								if (!SetPassword(ItemText,NULL))	// Change pwd value to null
									MessageBox(hDlg, L"Failed to clear the password, unknown error", L"Error",MB_OK);
								else
								{
									HKEY hkey;
									//
									// Dissable power-on dialog.
									//
									if (ERROR_SUCCESS!=RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("ControlPanel\\Owner"), 0, 0, 0, 0, 0, &hkey, 0 ))
										MessageBox(hDlg,L"Failed to open the Owner key",L"Error",MB_OK);

									if (ERROR_SUCCESS!=RegSetValueEx( hkey, TEXT("PowrPass"), 0, REG_BINARY, (CONST BYTE*)"\x00", 1 ))
										MessageBox(hDlg,L"Failed to clear Owner value",L"Error",MB_OK);

									RegCloseKey( hkey );
								}

							EndDialog( hDlg, 1 );
						}
						else
						{
							MessageBox(hDlg,L"XXInvalid Password - please enter Old Password",L"Error",MB_OK|MB_ICONHAND);
						}
					}
					break;
			}
			break;
	}

	return FALSE;
}


BOOL CALLBACK Verify_DlgProc( 
	HWND	hDlg, 
	UINT	uMsg, 
	WPARAM	wParam, 
	LPARAM	lParam )
{
	switch( uMsg )
	{
		case WM_INITDIALOG:
		{
			SHINITDLGINFO shidi;
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
			SetForegroundWindow( hDlg );

#if ( WIN32_PLATFORM_PSPC >= 310 )
			{
				//
				// Don't show "X" button on Pocket PC 2002 and later
				//
				DWORD dwStyle = GetWindowLong( hDlg, GWL_STYLE );
				dwStyle |= WS_NONAVDONEBUTTON;
				SetWindowLong( hDlg, GWL_STYLE, dwStyle );
			}
#endif
			SHSetNavBarText( hDlg, TEXT("Password") );
		}
		return FALSE;

		case WM_CLOSE:
			EndDialog( hDlg, 0 );
			return FALSE;

		case WM_COMMAND:
			switch( LOWORD(wParam) )
			{
				case IDC_LETMEIN:
					{
						// Check the password value and return appropriately
						wchar_t ItemText[MAX_PATH];
						GetDlgItemText(hDlg,IDC_PASSWORD,ItemText,MAX_PATH);
						EndDialog( hDlg, CheckPassword(ItemText));
					}
					break;
			}
			break;
	}
	return FALSE;
}

⌨️ 快捷键说明

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