static BOOL l_Alloc_DevInfo(_out PKLST_DEVINFO_HANDLE_INTERNAL* handleRef, _inopt HANDLE Heap)
{
	PKLST_DEVINFO_HANDLE_INTERNAL handle;

	*handleRef = NULL;

	handle = PoolHandle_Acquire_LstInfoK(Cleanup_DevInfo);
	ErrorNoSetAction(!IsHandleValid(handle), return FALSE, "->PoolHandle_Acquire_LstInfoK");

	if (Heap)
	{
		handle->DevInfoEL = HeapAlloc(Heap, HEAP_ZERO_MEMORY, sizeof(*handle->DevInfoEL));
		handle->Heap = Heap;
	}
	else
	{
		handle->DevInfoEL = Mem_Alloc(sizeof(*handle->DevInfoEL));
		handle->Heap = AllK->HeapDynamic;
	}

	ErrorMemory(!IsHandleValid(handle->DevInfoEL), Error);

	handle->DevInfoEL->DevInfoHandle = handle;
	*handleRef = handle;
	return TRUE;

Error:
	if (handle) PoolHandle_Dec_LstInfoK(handle);
	return FALSE;
}
Esempio n. 2
0
static int OnNtCreateSectionClick(HWND hDlg, UINT nIDCtrl)
{
    TFileTestData * pData = GetDialogData(hDlg);
    POBJECT_ATTRIBUTES pObjectAttributes = NULL;
    OBJECT_ATTRIBUTES ObjAttr;
    UNICODE_STRING SectionName;
    NTSTATUS Status;
    HANDLE FileHandle = NULL;

    // Close the section, if already open
    if(IsHandleValid(pData->hSection))
        OnNtCloseClick(hDlg);

    // Get the values from dialog controls to the dialog data
    if(SaveDialog1(hDlg) != ERROR_SUCCESS)
        return FALSE;

    // Format the object attributes
    if(pData->szSectionName[0] != 0)
    {
        InitializeObjectAttributes(&ObjAttr, &SectionName, OBJ_CASE_INSENSITIVE, NULL, NULL);
        RtlInitUnicodeString(&SectionName, pData->szSectionName);
        pObjectAttributes = &ObjAttr;
    }

    // Get the file handle for it
    if(IsHandleValid(pData->hFile))
        FileHandle = pData->hFile;

    // Either create a section or open one
    if(nIDCtrl == IDC_NTCREATE_SECTION)
    {
        Status = NtCreateSection(&pData->hSection,
                                  pData->dwSectDesiredAccess,
                                  pObjectAttributes,
                                 &pData->MaximumSize,
                                  pData->dwSectPageProtection,
                                  pData->dwSectAllocAttributes,
                                  FileHandle);
    }
    else
    {
        Status = NtOpenSection(&pData->hSection,
                                pData->dwSectDesiredAccess,
                                pObjectAttributes);
    }

    // Set the result info
    SetResultInfo(hDlg, Status, pData->hSection);
    UpdateDialog(hDlg, pData);
    return TRUE;
}
HFont FontMgr :: GetFont( const char* name, int size )
{
    std::string key( name );
    key.append("|", 1);
    key += itos(size);

    // insert/find
    NameIndexInsertRc rc =
        m_NameIndex.insert( std::make_pair( key, HFont() ) );
    if ( rc.second )
    {
        // this is a new insertion
        Graphics::OGL::Font* fnt = m_HandleMgr.Acquire( rc.first->second );
        if ( !fnt->Create( name, size ) )
        {
            m_HandleMgr.Release( rc.first->second );
            m_NameIndex.erase( rc.first );
            //IncReferences( rc.first->second );
            //DeleteFont( rc.first->second );
            //assert (false);
            return HFont();
        }
    }
    Lock(rc.first->second);

    if (IsHandleValid(rc.first->second))
        return ( rc.first->second );
    else
    {
        assert (false);
        return HFont();
    }
}
HTexture TextureMgr :: GetTexture( const char* name )
{
    // insert/find
    NameIndexInsertRc rc =
        m_NameIndex.insert( std::make_pair( Filesystem::GetFullPath(name), HTexture() ) );
    if ( rc.second )
    {
        // this is a new insertion
        Graphics::OGL::Texture* tex = m_HandleMgr.Acquire( rc.first->second );
        if ( !tex->Create( rc.first->first, true ) )
        {
            m_HandleMgr.Release( rc.first->second );
            m_NameIndex.erase( rc.first );
            //assert (false);
            return HTexture();
        }
    }
    Lock(rc.first->second);

    if (IsHandleValid(rc.first->second))
        return ( rc.first->second );
    else
    {
        assert (false);
        return HTexture();
    }
}
KUSB_EXP BOOL KUSB_API OvlK_Init(
    _out KOVL_POOL_HANDLE* PoolHandle,
    _in KUSB_HANDLE UsbHandle,
    _in INT MaxOverlappedCount,
    _inopt KOVL_POOL_FLAG Flags)
{
	PKOVL_POOL_HANDLE_INTERNAL handle = NULL;
	PKUSB_HANDLE_INTERNAL usbHandle;
	int i;

	*PoolHandle = NULL;

	ErrorParamAction(!IsHandleValid(PoolHandle), "PoolHandle", return FALSE);
	ErrorParamAction(MaxOverlappedCount > 256, "MaxOverlappedCount cannot be greater than 256", return FALSE);

	Pub_To_Priv_UsbK(UsbHandle, usbHandle, return FALSE);

	handle = PoolHandle_Acquire_OvlPoolK(Cleanup_OvlPoolK);
	ErrorNoSetAction(!IsHandleValid(handle), return FALSE, "->PoolHandle_Acquire_OvlPoolK");

	handle->Flags		= Flags;

	ErrorSet(!PoolHandle_Inc_UsbK(usbHandle), UsbHandleError, ERROR_RESOURCE_NOT_AVAILABLE, "->PoolHandle_Inc_UsbK");
	handle->UsbHandle	= usbHandle;

	handle->MasterArray		= Mem_Alloc(sizeof(KOVL_EL) * MaxOverlappedCount);
	ErrorMemory(!handle->MasterArray, Error);
	handle->MasterListCount = MaxOverlappedCount;

	for(i = 0; i < MaxOverlappedCount; i++)
	{
		DL_APPEND(handle->ReleasedList, &handle->MasterArray[i]);
	}

	handle->Flags		= Flags;

	*PoolHandle = (KOVL_POOL_HANDLE)handle;
	PoolHandle_Live_OvlPoolK(handle);
	return TRUE;

Error:
	PoolHandle_Dec_UsbK(usbHandle);
UsbHandleError:
	if (handle) PoolHandle_Dec_OvlPoolK(handle);
	return FALSE;
}
Esempio n. 6
0
static int OnSetActive(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    TCHAR szEaInfo[128];
    BOOL bEnabled = FALSE;
    int nChecked;

    // Set directory name and file name
    SetDlgItemText(hDlg, IDC_DIRECTORY_NAME, pData->szDirName);
    SetDlgItemText(hDlg, IDC_FILE_NAME, pData->szFileName1);

    // Convert both to NT name.
    if(GetWindowTextLength(GetDlgItem(hDlg, IDC_DIRECTORY_NAME)) == 0)
        ConvertToNtName(hDlg, IDC_FILE_NAME);
    ConvertToNtName(hDlg, IDC_DIRECTORY_NAME);

    // Set the various create options
    Hex2DlgText32(hDlg, IDC_OBJ_ATTR_FLAGS, pData->dwObjAttrFlags);
    Hex2DlgText32(hDlg, IDC_DESIRED_ACCESS, pData->dwDesiredAccess);
    Hex2DlgText64(hDlg, IDC_ALLOCATION_SIZE, pData->AllocationSize);
    Hex2DlgText32(hDlg, IDC_FILE_ATTRIBUTES, pData->dwFileAttributes);
    Hex2DlgText32(hDlg, IDC_SHARE_ACCESS, pData->dwShareAccess);
    Hex2DlgText32(hDlg, IDC_CREATE_OPTIONS, pData->dwCreateOptions);

    // Update the info about extended attributes
    rsprintf(szEaInfo, IDS_EA_INFO, pData->pFileEa, pData->dwEaSize);
    SetDlgItemText(hDlg, IDC_EXTENDED_ATTRIBUTES, szEaInfo);

    // Enable/disable transaction
    if(pfnRtlSetCurrentTransaction != NULL && IsHandleValid(pData->hTransaction))
        bEnabled = TRUE;
    EnableDlgItems(hDlg, bEnabled, IDC_TRANSACTED, 0);
    if(bEnabled)
        CheckDlgButton(hDlg, IDC_TRANSACTED, pData->bUseTransaction);

    // Check/uncheck virtualization
    nChecked = TokenVirtualization(TOKEN_VIRT_QUERY, 0);
    CheckDlgButton(hDlg, IDC_VIRTUALIZATION, nChecked);

    // Enable/disable "NtClose"
    bEnabled = IsHandleValid(pData->hFile) ? TRUE : FALSE;
    EnableDlgItems(hDlg, bEnabled, IDC_CLOSE_HANDLE, 0);
    return TRUE;
}
Esempio n. 7
0
static void UpdateDialog(HWND hDlg, TFileTestData * pData)
{
    BOOL bEnable;

    // The mapping buttons are only allowed if we have valid map handle
    bEnable = IsHandleValid(pData->hSection) ? TRUE : FALSE;
    EnableDlgItems(hDlg, bEnable, IDC_NTCLOSE, IDC_MAP_VIEW, 0);

    // The map accessing is only allowed if we have valid mapping
    EnableDlgItems(hDlg, pData->bSectionViewMapped, IDC_DATA_EDITOR, IDC_UNMAP_VIEW, 0);
}
Esempio n. 8
0
static int OnSetActive(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    BOOL bEnabled = FALSE;
    int nChecked;

    // Set directory name
    SetDlgItemText(hDlg, IDC_DIRECTORY_NAME, pData->szDirName);
    ConvertToWin32Name(hDlg, IDC_DIRECTORY_NAME);
    
    // Set file name
    if((pData->dwCreateOptions & FILE_OPEN_BY_FILE_ID) == 0)
    {
        SetDlgItemText(hDlg, IDC_FILE_NAME, pData->szFileName1);
        ConvertToWin32Name(hDlg, IDC_FILE_NAME);
    }

    // Set template file
    SetDlgItemText(hDlg, IDC_TEMPLATE_FILE, pData->szTemplate);
    ConvertToWin32Name(hDlg, IDC_TEMPLATE_FILE);

    // Set the various create options
    Hex2DlgText32(hDlg, IDC_DESIRED_ACCESS, pData->dwDesiredAccess);
    Hex2DlgText32(hDlg, IDC_FILE_ATTRIBUTES, pData->dwFileAttributes);
    Hex2DlgText32(hDlg, IDC_SHARE_ACCESS, pData->dwShareAccess);

    // Enable/disable transaction
    bEnabled = (pfnCreateFileTransacted != NULL && IsHandleValid(pData->hTransaction));
    EnableDlgItems(hDlg, bEnabled, IDC_TRANSACTED, 0);
    nChecked = (bEnabled && pData->bUseTransaction) ? BST_CHECKED : BST_UNCHECKED;
    CheckDlgButton(hDlg, IDC_TRANSACTED, nChecked);

    // Check/uncheck virtualization
    nChecked = TokenVirtualization(TOKEN_VIRT_QUERY, 0);
    CheckDlgButton(hDlg, IDC_VIRTUALIZATION, nChecked);

    // Enable/disable "CloseHandle"
    bEnabled = IsHandleValid(pData->hFile) ? TRUE : FALSE;
    EnableDlgItems(hDlg, bEnabled, IDC_CLOSE_HANDLE, 0);
    return TRUE;
}
Esempio n. 9
0
static int OnNtCloseClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    NTSTATUS Status = STATUS_SUCCESS;

    // Invoke breakpoint if the user wants to
    if(IsDlgButtonChecked(hDlg, IDC_BREAKPOINT) == BST_CHECKED)
        DebugBreak();

    // Close file handle first
    if(IsHandleValid(pData->hFile))
        Status = NtClose(pData->hFile);
    pData->hFile = NULL;
    
    // Close directory handle last
    if(IsHandleValid(pData->hDirectory))
        NtClose(pData->hDirectory);
    pData->hDirectory = NULL;

    SetResultInfo(hDlg, Status, NULL, 0xFFFFFFFF);
    return TRUE;
}
Esempio n. 10
0
static int OnSetActive(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    HANDLE FileHandle = IsHandleValid(pData->hFile) ? pData->hFile : NULL;

    // Either set NULL or the handle value
    if(FileHandle == NULL)
        SetDlgItemText(hDlg, IDC_FILE_HANDLE, _T("NULL"));
    else
        Hex2DlgTextPtr(hDlg, IDC_FILE_HANDLE, (DWORD_PTR)FileHandle);

    UpdateDialog(hDlg, pData);
    return TRUE;
}
Esempio n. 11
0
static int OnNtCloseClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    NTSTATUS Status = STATUS_SUCCESS;

    // Close the handle
    if(IsHandleValid(pData->hSection))
        Status = NtClose(pData->hSection);
    pData->hSection = NULL;

    // Set the result info
    SetResultInfo(hDlg, Status, pData->hSection);
    UpdateDialog(hDlg, pData);
    return TRUE;
}
// This function enables/disables the buttons for map operations
static int UpdateDialogButtons(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    BOOL bEnable = IsHandleValid(pData->hFile) ? TRUE : FALSE;

    EnableDlgItems(hDlg, bEnable, 
                         IDC_FLUSH_FILE_BUFFERS,
                         IDC_SET_SPARSE,
                         IDC_REQUEST_OPLOCK_MENU,
                         IDC_BREAK_ACKNOWLEDGE_1,
                         IDC_REQUEST_OPLOCK_WIN7,
                         IDC_BREAK_ACKNOWLEDGE_2,
                         0);
    return TRUE;
}
Esempio n. 13
0
KUSB_EXP BOOL KUSB_API OvlK_Acquire(
    _out KOVL_HANDLE* OverlappedK,
    _in KOVL_POOL_HANDLE PoolHandle)
{
	PKOVL_EL overlappedEL = NULL;
	PKOVL_POOL_HANDLE_INTERNAL handle;
	BOOL isNewFromPool = FALSE;

	ErrorParamAction(!IsHandleValid(OverlappedK), "OverlappedK", return FALSE);
	*OverlappedK = NULL;

	Pub_To_Priv_OvlPoolK(PoolHandle, handle, return FALSE);
	ErrorSetAction(!PoolHandle_Inc_OvlPoolK(handle), ERROR_RESOURCE_NOT_AVAILABLE, return FALSE, "->PoolHandle_Inc_OvlPoolK");

	overlappedEL = handle->ReleasedList;
	ErrorSetAction(!overlappedEL, ERROR_NO_MORE_ITEMS, PoolHandle_Dec_OvlPoolK(handle); return FALSE, "No more overlapped handles");

	DL_DELETE(handle->ReleasedList, overlappedEL);
	if (!overlappedEL->Handle)
	{
		isNewFromPool = TRUE;
		// Get a new OverlappedK handle.
		overlappedEL->Handle = PoolHandle_Acquire_OvlK(Cleanup_OvlK);
		if (!overlappedEL->Handle)
		{
			DL_PREPEND(handle->ReleasedList, overlappedEL);
			ErrorNoSet(!overlappedEL->Handle, Error, "->PoolHandle_Acquire_OvlK");
		}
	}

	overlappedEL->Handle->MasterLink = overlappedEL;
	overlappedEL->Handle->Pool = handle;
	o_Reuse(overlappedEL->Handle);

	*OverlappedK = (KOVL_HANDLE)overlappedEL->Handle;
	if (isNewFromPool) PoolHandle_Live_OvlK(overlappedEL->Handle);

	overlappedEL->Handle->IsAcquired = 1;
	DL_APPEND(handle->AcquiredList, overlappedEL);

	PoolHandle_Dec_OvlPoolK(handle);
	return TRUE;
Error:
	PoolHandle_Dec_OvlPoolK(handle);
	return FALSE;
}
static BOOL l_EnumKey_Instances(KUSB_ENUM_REGKEY_PARAMS* RegEnumParams)
{
	LONG status;
	PKLST_DEVINFO_EL newDevItem = NULL;
	HDEVINFO hDevInfo = NULL;
	DWORD length;
	DWORD iDeviceInterface = (DWORD) - 1;

	if (!RegEnumParams->Exclusive.DevInterfaceGuid)
	{
		// Apply DeviceInterfaceGUID filter:
		mLst_ApplyPatternMatch(RegEnumParams->PatternMatch, DeviceInterfaceGUID, RegEnumParams->TempItem->DeviceInterfaceGUID, goto NextInstance);

		hDevInfo = SetupDiGetClassDevsA(&RegEnumParams->DevInterfaceGuid, RegEnumParams->TempItem->DeviceID, NULL, RegEnumParams->DigcFlags | DIGCF_DEVICEINTERFACE);
		if (!IsHandleValid(hDevInfo))
		{
			USBDBGN("SetupDiGetClassDevsA Failed. ErrorCode:%08Xh", GetLastError());
			return TRUE;
		}
	}
Esempio n. 15
0
static int OnSetActive(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    BOOL bEnable = FALSE;

    if(IsHandleValid(pData->hFile))
        bEnable = TRUE;

    EnableDlgItems(hDlg, bEnable, IDC_READ_FILE,
                   IDC_WRITE_FILE,
                   IDC_NTREAD_FILE,
                   IDC_NTWRITE_FILE,
                   IDC_LOCK_FILE,
                   IDC_UNLOCK_FILE,
                   IDC_NTLOCK_FILE,
                   IDC_NTUNLOCK_FILE,
                   IDC_GET_FILE_SIZE,
                   IDC_SET_FILE_POINTER,
                   IDC_SET_END_OF_FILE,
                   0);
    return TRUE;
}
Esempio n. 16
0
static int OnCloseHandleClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    int nError = ERROR_SUCCESS;

    if(IsHandleValid(pData->hFile))
    {
        // If directory has been changed, set it back to initial
        if(pData->szDirName[0] != 0)
            SetCurrentDirectory(g_szInitialDirectory);

        // Invoke breakpoint if the user wants to
        if(IsDlgButtonChecked(hDlg, IDC_BREAKPOINT) == BST_CHECKED)
            DebugBreak();

        if(!CloseHandle(pData->hFile))
            nError = GetLastError();
    }

    pData->hFile = NULL;
    SetResultInfo(hDlg, nError, pData->hFile);
    return TRUE;
}
Esempio n. 17
0
static int OnCreateFileClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    OBJECT_ATTRIBUTES ObjAttr;
    IO_STATUS_BLOCK IoStatus;
    UNICODE_STRING FileName;
    UNICODE_STRING DirName;
    LARGE_INTEGER AllocationSize;
    NTSTATUS Status = STATUS_SUCCESS;
    HANDLE SaveTransactionHandle = NULL;
    TCHAR szFileName[MAX_NT_PATH];
    TCHAR szDirName[MAX_NT_PATH];
    DWORD cbObjectID = 0;
    BYTE ObjectID[0x10];

    // Close the handle, if already open
    if(IsHandleValid(pData->hDirectory) || IsHandleValid(pData->hFile))
        OnNtCloseClick(hDlg);

    // Get the various create options
    if(SaveDialog(hDlg) != ERROR_SUCCESS)
        return FALSE;

    if(pData->bUseTransaction && pfnRtlSetCurrentTransaction != NULL)
    {
        SaveTransactionHandle = pfnRtlGetCurrentTransaction();
        pfnRtlSetCurrentTransaction(pData->hTransaction);
    }

    // Get the directory name from the dialog data
    StringCchCopy(szDirName, _countof(szDirName), pData->szDirName);
    StringCchCopy(szFileName, _countof(szFileName), pData->szFileName1);

    // If we are about to open a file by ID, and we have no relative directory,
    // try to take the directory from the file name
    if(szDirName[0] == 0 && (pData->dwCreateOptions & FILE_OPEN_BY_FILE_ID))
    {
        LPTSTR szFullName = pData->szFileName1;
        LPTSTR szFileId = _tcsrchr(szFullName, _T('\\'));
        size_t nLength = szFileId - szFullName + 1;

        if(szFileId != NULL)
        {
            StringCchCopy(szDirName, nLength, szFullName);
            StringCchCopy(szFileName, _countof(szFileName), szFileId + 1);
        }
    }

    // Open the relative file (if any)
    if(szDirName[0] != 0)
    {
        RtlInitUnicodeString(&DirName, szDirName);
        InitializeObjectAttributes(&ObjAttr, &DirName, pData->dwObjAttrFlags, 0, NULL);
        Status = NtOpenFile(&pData->hDirectory,
                             pData->dwDesiredAccessRF,
                            &ObjAttr,
                            &IoStatus,
                             pData->dwShareAccessRF,
                             pData->dwOpenOptionsRF);

        if(!NT_SUCCESS(Status))
        {
            SetResultInfo(hDlg, Status, NULL, IoStatus.Information);
            return TRUE;
        }
    }

    // Prepare the file open
    if(NT_SUCCESS(Status))
    {
        RtlInitUnicodeString(&FileName, szFileName);

        // If open by ID required, set the ID to the string
        if(pData->dwCreateOptions & FILE_OPEN_BY_FILE_ID)
        {
            // Convert object ID to binary value
            if(StringToFileID(szFileName, NULL, ObjectID, &cbObjectID) != ERROR_SUCCESS)
                return TRUE;

            // Set the object ID to the UNICODE_STRING
            FileName.MaximumLength = 
            FileName.Length = (USHORT)cbObjectID;
            FileName.Buffer = (PWSTR)ObjectID;
        }

        ZeroMemory(&IoStatus, sizeof(IO_STATUS_BLOCK));
        InitializeObjectAttributes(&ObjAttr, &FileName, pData->dwObjAttrFlags, pData->hDirectory, NULL);
        AllocationSize.QuadPart = (LONGLONG)pData->AllocationSize;
           
        // Invoke breakpoint if the user wants to
        if(IsDlgButtonChecked(hDlg, IDC_BREAKPOINT) == BST_CHECKED)
            DebugBreak();

        Status = NtCreateFile(&pData->hFile,
                               pData->dwDesiredAccess,
                              &ObjAttr,
                              &IoStatus,
                              &AllocationSize,
                               pData->dwFileAttributes,
                               pData->dwShareAccess,
                               pData->dwCreateDisposition2,
                               pData->dwCreateOptions,
                               pData->pFileEa,
                               pData->dwEaSize);
        SetResultInfo(hDlg, Status, pData->hFile, IoStatus.Information);

        // If this operation failed, we close the directory as well
        if(!NT_SUCCESS(Status) && pData->hDirectory != NULL)
        {
            NtClose(pData->hDirectory);
            pData->hDirectory = NULL;
        }
    }

    if(pData->bUseTransaction && pfnRtlSetCurrentTransaction != NULL)
    {
        pfnRtlSetCurrentTransaction(SaveTransactionHandle);
        SaveTransactionHandle = NULL;
    }

    return TRUE;
}
Esempio n. 18
0
static int OnCreateFileClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    HANDLE hTemplateFile = NULL;
    int nError = ERROR_SUCCESS;

    // Close the handle, if already open
    if(IsHandleValid(pData->hFile))
        OnCloseHandleClick(hDlg);

    // Get the values from dialog controls to the dialog data
    if(SaveDialog(hDlg) != ERROR_SUCCESS)
        return FALSE;

    // Change the directory (If any)
    if(pData->szDirName[0] != 0)
    {
        if(!SetCurrentDirectory(pData->szDirName))
        {
            nError = GetLastError();
            SetResultInfo(hDlg, nError, INVALID_HANDLE_VALUE);
            return TRUE;
        }
    }

    // Prepare the template file
    if(nError == ERROR_SUCCESS && pData->szTemplate[0] != 0)
    {
        hTemplateFile = CreateFile(pData->szTemplate,
                                   FILE_READ_EA,
                                   FILE_SHARE_READ,
                                   NULL,
                                   OPEN_EXISTING,
                                   0,
                                   NULL);
        if(hTemplateFile == INVALID_HANDLE_VALUE)
            nError = GetLastError();
    }

    // Prepare the file open
    if(nError == ERROR_SUCCESS)
    {
        if(pData->bUseTransaction == FALSE)
        {
            // Invoke breakpoint if the user wants to
            if(IsDlgButtonChecked(hDlg, IDC_BREAKPOINT) == BST_CHECKED)
                DebugBreak();

            pData->hFile = CreateFile(pData->szFileName1,
                                      pData->dwDesiredAccess,
                                      pData->dwShareAccess,
                                      NULL,
                                      pData->dwCreateDisposition1,
                                      pData->dwFileAttributes,
                                      hTemplateFile);
        }
        else
        {
            // Invoke breakpoint if the user wants to
            if(IsDlgButtonChecked(hDlg, IDC_BREAKPOINT) == BST_CHECKED)
                DebugBreak();

            pData->hFile = pfnCreateFileTransacted(pData->szFileName1,
                                                   pData->dwDesiredAccess,
                                                   pData->dwShareAccess,
                                                   NULL,
                                                   pData->dwCreateDisposition1,
                                                   pData->dwFileAttributes,
                                                   hTemplateFile,
                                                   pData->hTransaction,
                                                   NULL,
                                                   NULL);
        }

        if(IsHandleInvalid(pData->hFile))
            nError = GetLastError();
    }

    if(IsHandleValid(hTemplateFile))
        CloseHandle(hTemplateFile);
    SetResultInfo(hDlg, nError, pData->hFile);
    return TRUE;
}