I. Quels sont les deux composants de Windows 7 qui tirent profit du mode Transactionnel ?▲
Les deux composants qui tirent profit du mode transactionnel dans Windows 7 sont, le gestionnaire de fichiers NTFS, la technologie s'appelle TxF et le registre Windows (TxR). Ces deux composants s'appuient sur le Kernel Transaction Manager.
Pour en savoir plus : http://msdn.microsoft.com/fr-fr/visualc/bb880520.aspx
HMODULE hmodule =LoadLibrary(L"ktmw32.dll");
CREATETRANSACTION pCreateTransaction ;
ROLLBACKTRANSACTION pRollbackTransaction;
COMMITTRANSACTION pCommitTransaction;
HANDLE htransaction=NULL ;
HANDLE hfile=NULL;
CString cs;
if (NULL ==hmodule)
{
MessageBox(L"Ne trouve pas ktmw32.dll",L"",0);
goto cleanup;
}
pCreateTransaction=(CREATETRANSACTION)GetProcAddress (hmodule,"CreateTransaction");
if (NULL ==pCreateTransaction)
{
MessageBox(L"Ne trouve pas la méthode CreateTransaction",L"",0);
goto cleanup;
}
pRollbackTransaction=(ROLLBACKTRANSACTION)GetProcAddress(hmodule,"RollbackTransaction");
if (NULL ==pRollbackTransaction)
{
MessageBox(L"Ne trouve pas la méthode RollbackTransaction",L"",0);
goto cleanup;
}
pCommitTransaction=(COMMITTRANSACTION)GetProcAddress(hmodule,"CommitTransaction");
if (NULL ==pCommitTransaction)
{
MessageBox(L"Ne trouve pas la méthode CommitTransaction",L"",0);
goto cleanup;
}
htransaction =(pCreateTransaction) (NULL, 0, TRANSACTION_DO_NOT_PROMOTE, 0, 0, NULL, L"Description de la Transaction");
if (NULL==htransaction)
{
MessageBox(L"Ne peut créer de transaction",L"",0);
goto cleanup;
}
hfile=CreateFileTransacted(L"TestTransaction.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0, htransaction, 0, 0);
if (NULL==hfile)
{
MessageBox(L"Ne peut ouvrir le fichier spécifié",L"",0);
goto cleanup;
}
m_Edit.GetWindowTextW (cs);
const wchar_t *buffer=cs.GetString ();
DWORD pnumBytes;
DWORD npb=cs.GetLength ()*2;
BOOL b=WriteFile(hfile,buffer,npb,&pnumBytes,NULL);
if (b==FALSE)
{
DWORD error=GetLastError ();
MessageBox(L"Ne peut écrire dans le fichier spécifié",L"",0);
goto cleanup;
}
if (m_checktransaction)
b=(pCommitTransaction)(htransaction);
else
b=(pRollbackTransaction)(htransaction);
if (b==FALSE)
{
MessageBox(L"Ne peut valider la transaction",L"Test TxF",0);
}if (hfile)
{
CloseHandle(hfile);
}
if (htransaction)
{
CloseHandle(htransaction);
}
if (hmodule)
{
FreeLibrary (hmodule);
}Pour plus d'infos :
- MSDN : http://msdn.microsoft.com/fr-fr/windows/default.aspx
- Le coach Windows 7 : http://msdn.microsoft.com/fr-fr/windows/msdn.coach.windows7
- Kit de développement pour Windows 7 : http://msdn.microsoft.com/fr-fr/windows/gg398052.aspx




