> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CreateFence

> Creates a fence object. (ID3D12Device.CreateFence)

Creates a fence object.

## Syntax

```cpp theme={null}
HRESULT CreateFence(
    UINT64 InitialValue,
    D3D12_FENCE_FLAGS Flags,
    const IID & riid,
    void  ppFence
)
```

### Parameters

*InitialValue*\
Type: UINT64

The initial value for the fence.

*Flags*\
Type: D3D12\_FENCE\_FLAGS

A combination of [D3D12\_FENCE\_FLAGS](/reference/graphics/d3d12/enums/d3d12_fence_flags_public)-typed values that are combined by using a bitwise OR operation.
The resulting value specifies options for the fence.

*riid*\
Type: const IID &

The globally unique identifier (**GUID**) for the fence interface ([ID3D12Fence](/reference/graphics/d3d12/interfaces/id3d12fence/id3d12fence_public)).
The **REFIID**, or **GUID**, of the interface to the fence can be obtained by using the \_\_uuidof() macro.
For example, \_\_uuidof(ID3D12Fence) will get the **GUID** of the interface to a fence.

*ppFence \[out]*\
Type: void \*\*

A pointer to a memory block that receives a pointer to the [ID3D12Fence](/reference/graphics/d3d12/interfaces/id3d12fence/id3d12fence_public) interface that is used to access the fence.

### Return value

Type: HRESULT

Returns **S\_OK** if successful; otherwise, returns one of the [Direct3D 12 Return Codes](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues).

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h\
**Library:** d3d12\_xs.lib or d3d12\_x.lib\
**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

[ID3D12Device](/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [D3D12_FENCE_FLAGS](/reference/graphics/d3d12/enums/d3d12_fence_flags_public.md)
- [ID3D12Fence1](/reference/graphics/d3d12/interfaces/id3d12fence1/id3d12fence1_public.md)
- [GetCreationFlags](/reference/graphics/d3d12/interfaces/id3d12fence1/methods/id3d12fence1_getcreationflags_public.md)
- [GetStatusFence](/reference/graphics/d3d12/interfaces/id3d12protectedsession/methods/id3d12protectedsession_getstatusfence_public.md)
- [ID3D12Fence](/reference/graphics/d3d12/interfaces/id3d12fence/id3d12fence_public.md)
