本文整理汇总了C++中microsoft::wrl::ComPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr类的具体用法?C++ ComPtr怎么用?C++ ComPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void D2DComponent::BeginDraw(Windows::Foundation::Rect updateRect)
{
Microsoft::WRL::ComPtr<IDXGISurface> surface;
POINT offset;
RECT updateRectNative =
{
(LONG)updateRect.Left,
(LONG)updateRect.Top,
(LONG)updateRect.Right,
(LONG)updateRect.Bottom
};
HRESULT beginDrawHR = _sisNative->BeginDraw(updateRectNative, &surface, &offset);
if (beginDrawHR == DXGI_ERROR_DEVICE_REMOVED || beginDrawHR == DXGI_ERROR_DEVICE_RESET)
{
CreateDeviceResources();
BeginDraw(updateRect);
}
else
{
ThrowIfFailed(beginDrawHR);
}
Microsoft::WRL::ComPtr<ID2D1Bitmap1> bitmap;
ThrowIfFailed(_d2dDeviceContext->CreateBitmapFromDxgiSurface(surface.Get(), nullptr, &bitmap));
_d2dDeviceContext->BeginDraw();
_d2dDeviceContext->SetTarget(bitmap.Get());
}
示例2: GetSelection
IFACEMETHODIMP CTriColorControlProvider::GetSelection(_Outptr_result_maybenull_ SAFEARRAY * *retVal)
{
*retVal = nullptr;
HRESULT hr = CheckDisconnected();
if (SUCCEEDED(hr))
{
TriColorValue controlValue;
hr = m_control->get_ControlValue(&controlValue);
if (SUCCEEDED(hr))
{
ComPtr<IInspectable> spFragmentProvider;
hr = m_control->GetTriColorFragmentProvider(controlValue, &spFragmentProvider);
if (SUCCEEDED(hr))
{
*retVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1);
if (*retVal != nullptr)
{
long index = 0;
hr = SafeArrayPutElement(*retVal, &index, spFragmentProvider.Get());
if (FAILED(hr))
{
SafeArrayDestroy(*retVal);
*retVal = nullptr;
}
}
else
{
hr = E_OUTOFMEMORY;
}
}
}
}
return hr;
}
示例3: GetFloatProperty
//-------------------------------------------------------------------
// GetFloatProperty
//
//-------------------------------------------------------------------
float CObjectFinderEffect::GetFloatProperty(
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable *>> &spSetting,
const HSTRING &key, boolean &found)
{
float value = 0.0f;
spSetting->HasKey(key, &found);
IInspectable* valueAsInsp = NULL;
if (found)
{
spSetting->Lookup(key, &valueAsInsp);
}
if (valueAsInsp)
{
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IPropertyValue> pPropertyValue;
HRESULT hr = valueAsInsp->QueryInterface(IID_PPV_ARGS(&pPropertyValue));
if (!FAILED(hr))
{
hr = pPropertyValue->GetSingle(&value);
}
}
return value;
}
示例4: Navigate
IFACEMETHODIMP CTriColorControlProvider::Navigate(_In_ NavigateDirection direction, _Outptr_result_maybenull_ IRawElementProviderFragment ** retVal)
{
*retVal = nullptr;
ComPtr<IInspectable> spFragment;
HRESULT hr = CheckDisconnected();
if (SUCCEEDED(hr))
{
if (direction == NavigateDirection_Parent)
{
hr = m_control->GetAppWindowProvider(&spFragment);
}
else if (direction == NavigateDirection_FirstChild)
{
hr = m_control->GetTriColorFragmentProvider(TriColorValue::Red, &spFragment);
}
else if (direction == NavigateDirection_LastChild)
{
hr = m_control->GetTriColorFragmentProvider(TriColorValue::Green, &spFragment);
}
}
if (SUCCEEDED(hr) && spFragment != nullptr)
{
hr = spFragment.Get()->QueryInterface(IID_PPV_ARGS(retVal));
}
// For the other directions (next, previous) the default of nullptr is correct
return hr;
}
示例5: CreateVertexBuffer
void BasicShapes::CreateVertexBuffer(
_In_ unsigned int numVertices,
_In_ BasicVertex *vertexData,
_Out_ ID3D11Buffer **vertexBuffer
)
{
*vertexBuffer = nullptr;
Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBufferInternal;
D3D11_BUFFER_DESC VertexBufferDesc;
VertexBufferDesc.ByteWidth = sizeof(BasicVertex) * numVertices;
VertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
VertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
VertexBufferDesc.CPUAccessFlags = 0;
VertexBufferDesc.MiscFlags = 0;
VertexBufferDesc.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA VertexBufferData;
VertexBufferData.pSysMem = vertexData;
VertexBufferData.SysMemPitch = 0;
VertexBufferData.SysMemSlicePitch = 0;
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&VertexBufferDesc,
&VertexBufferData,
&vertexBufferInternal
)
);
*vertexBuffer = vertexBufferInternal.Detach();
}
示例6: CreateIndexBuffer
void BasicShapes::CreateIndexBuffer(
_In_ unsigned int numIndices,
_In_ unsigned short *indexData,
_Out_ ID3D11Buffer **indexBuffer
)
{
*indexBuffer = nullptr;
Microsoft::WRL::ComPtr<ID3D11Buffer> indexBufferInternal;
D3D11_BUFFER_DESC IndexBufferDesc;
IndexBufferDesc.ByteWidth = sizeof(unsigned short) * numIndices;
IndexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
IndexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
IndexBufferDesc.CPUAccessFlags = 0;
IndexBufferDesc.MiscFlags = 0;
IndexBufferDesc.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA IndexBufferData;
IndexBufferData.pSysMem = indexData;
IndexBufferData.SysMemPitch = 0;
IndexBufferData.SysMemSlicePitch = 0;
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&IndexBufferDesc,
&IndexBufferData,
&indexBufferInternal
)
);
*indexBuffer = indexBufferInternal.Detach();
}
示例7: decrypt
plaintext_string winrt_encryption::decrypt() const
{
// To fully guarantee asynchrony would require significant impact on existing code. This code path
// is never run on a user's thread and is only done once when setting up a connection.
auto encrypted = m_buffer.get();
auto provider = ref new Windows::Security::Cryptography::DataProtection::DataProtectionProvider();
auto plaintext = pplx::create_task(provider->UnprotectAsync(encrypted)).get();
// Get access to raw bytes in plain text buffer.
Microsoft::WRL::ComPtr<IInspectable> bufferInspectable(reinterpret_cast<IInspectable *>(plaintext));
Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
bufferInspectable.As(&bufferByteAccess);
byte * rawPlaintext;
const auto &result = bufferByteAccess->Buffer(&rawPlaintext);
if (result != S_OK)
{
throw ::utility::details::create_system_error(result);
}
// Construct string and zero out memory from plain text buffer.
auto data = plaintext_string(new std::wstring(
reinterpret_cast<const std::wstring::value_type *>(rawPlaintext),
plaintext->Length / 2));
SecureZeroMemory(rawPlaintext, plaintext->Length);
return std::move(data);
}
示例8: Create
Handle Create(size_t hash, const void* data, size_t data_size, ID3D11Device* device) {
auto cached_handle = g_cache_.Get(hash);
if (cached_handle.IsValid()) {
return cached_handle;
}
D3D11_BUFFER_DESC bufferDesc;
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.ByteWidth = data_size;
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA bufferData;
ZeroMemory(&bufferData, sizeof(bufferData));
bufferData.pSysMem = data;
Microsoft::WRL::ComPtr<ID3D11Buffer> buffer;
HRESULT create_buffer_result = device->CreateBuffer(&bufferDesc, &bufferData, buffer.GetAddressOf());
if (FAILED(create_buffer_result)) {
DXFW_DIRECTX_TRACE(__FILE__, __LINE__, true, create_buffer_result);
return {};
}
auto new_handle = g_storage_.Add(buffer);
g_cache_.Set(hash, new_handle);
return new_handle;
}
示例9: Create
void Model::Create()
{
CreateRootSignature();
CreatePipelineState();
Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CommandAllocator;
Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> CommandList;
Microsoft::WRL::ComPtr<ID3D12Resource> VertexUploadResource;
Microsoft::WRL::ComPtr<ID3D12Resource> IndexUploadResource;
GPUFence Fence;
Fence.Initialize(DeviceContext.GetDevice());
Utility::ThrowOnFail(DeviceContext.GetDevice()->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&CommandAllocator)));
Utility::ThrowOnFail(DeviceContext.GetDevice()->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, CommandAllocator.Get(), nullptr, IID_PPV_ARGS(&CommandList)));
UploadVertices(CommandList, VertexUploadResource);
UploadIndices(CommandList, IndexUploadResource);
Utility::ThrowOnFail(CommandList->Close());
ID3D12CommandList * CommandListPointer = CommandList.Get();
DeviceContext.GetCommandQueue()->ExecuteCommandLists(1, &CommandListPointer);
Fence.SetAndWait(DeviceContext.GetCommandQueue());
}
示例10: CompileShaderFromFile
HRESULT CompileShaderFromFile(const std::wstring &file
, const StageInfo &info, ID3D10Blob** ppBlobOut)
{
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif//defiend(DEBUG) || defined(_DEBUG)
#if defined(NDEBUG) || defined(_NDEBUG)
dwShaderFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
#endif//defined(NDEBUG) || defined(_NDEBUG)
Microsoft::WRL::ComPtr<ID3DBlob> pErrorBlob;
auto hr = D3DCompileFromFile(
file.c_str()
, NULL
, D3D_COMPILE_STANDARD_FILE_INCLUDE
, info.entrypoint.c_str()
, info.model.c_str()
, dwShaderFlags
, 0
, ppBlobOut
, pErrorBlob.GetAddressOf()
);
if ( FAILED( hr ) ) {
if (pErrorBlob) {
// エラーメッセージを出力.
OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
}
}
return hr;
}
示例11: CreateDepthStencilView
ID3D11DepthStencilView* CreateDepthStencilView(ID3D11Device* pDevice,DWORD dwWidth, DWORD dwHeight)
{
HRESULT hr;
ID3D11DepthStencilView* pDSV = nullptr;
Microsoft::WRL::ComPtr<ID3D11Texture2D> pDSTexture = nullptr;
D3D11_TEXTURE2D_DESC DescDepth;
DescDepth.Width = dwWidth;
DescDepth.Height = dwHeight;
DescDepth.MipLevels = 1;
DescDepth.ArraySize = 1;
DescDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
DescDepth.SampleDesc.Count = 1;
DescDepth.SampleDesc.Quality = 0;
DescDepth.Usage = D3D11_USAGE_DEFAULT;
DescDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
DescDepth.CPUAccessFlags = 0;
DescDepth.MiscFlags = 0;
if (FAILED(hr = pDevice->CreateTexture2D(&DescDepth, NULL, &pDSTexture)))
{
return nullptr;
}
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;
ZeroMemory(&dsvd, sizeof(dsvd));
dsvd.Format = DescDepth.Format;
dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
dsvd.Texture2D.MipSlice = 0;
if (FAILED(hr = pDevice->CreateDepthStencilView(
pDSTexture.Get(), &dsvd, &pDSV)))
{
return nullptr;
}
return pDSV;
}
示例12: CreatePipelineState
void Model::CreatePipelineState()
{
Microsoft::WRL::ComPtr<ID3DBlob> VertexShader;
Microsoft::WRL::ComPtr<ID3DBlob> PixelShader;
LoadAndCompileShader(VertexShader, PixelShader);
std::array<D3D12_INPUT_ELEMENT_DESC, 2> InputElementDesc
{ {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
} };
D3D12_GRAPHICS_PIPELINE_STATE_DESC PipelineStateDesc = {};
PipelineStateDesc.InputLayout = { InputElementDesc.data(), static_cast<UINT>(InputElementDesc.size()) };
PipelineStateDesc.pRootSignature = RootSignature.Get();
PipelineStateDesc.VS = CD3DX12_SHADER_BYTECODE(VertexShader.Get());
PipelineStateDesc.PS = CD3DX12_SHADER_BYTECODE(PixelShader.Get());
PipelineStateDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
PipelineStateDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
PipelineStateDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
PipelineStateDesc.SampleMask = UINT_MAX;
PipelineStateDesc.SampleDesc.Count = 1;
PipelineStateDesc.NumRenderTargets = 1;
PipelineStateDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
PipelineStateDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT;
PipelineStateDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
Utility::ThrowOnFail(DeviceContext.GetDevice()->CreateGraphicsPipelineState(&PipelineStateDesc, IID_PPV_ARGS(&PipelineState)));
}
示例13: Shape
RoundedRectangle::RoundedRectangle(FLOAT x, FLOAT y, FLOAT width, FLOAT height,
FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::RoundedRectangle),
m_X(x),
m_Y(y),
m_Width(width + x),
m_Height(height + y),
m_XRadius(xRadius),
m_YRadius(yRadius)
{
HRESULT hr = E_FAIL;
const D2D1_ROUNDED_RECT rect = { m_X, m_Y, m_Width, m_Height, m_XRadius, m_YRadius };
Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> rectangle;
hr = Canvas::c_D2DFactory->CreateRoundedRectangleGeometry(rect, rectangle.GetAddressOf());
if (FAILED(hr))
{
LogErrorF(
L"Could not create rounded rectangle object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i",
(int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius);
return;
}
hr = rectangle.CopyTo(m_Shape.GetAddressOf());
if (FAILED(hr)) LogErrorF(
L"Could not copy rounded rectangle object to shape object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i",
(int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius);
}
示例14: Shape
Arc::Arc(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, FLOAT xRadius, FLOAT yRadius, FLOAT angle,
D2D1_SWEEP_DIRECTION sweep, D2D1_ARC_SIZE size, D2D1_FIGURE_END ending) : Shape(ShapeType::Arc),
m_StartPoint(D2D1::Point2F(x1, y1)),
m_ArcSegment(D2D1::ArcSegment(
D2D1::Point2F(x2, y2),
D2D1::SizeF(xRadius, yRadius),
angle,
sweep,
size)),
m_ShapeEnding(ending)
{
Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink;
Microsoft::WRL::ComPtr<ID2D1PathGeometry> path;
HRESULT hr = Canvas::c_D2DFactory->CreatePathGeometry(path.GetAddressOf());
if (SUCCEEDED(hr))
{
hr = path->Open(sink.GetAddressOf());
if (SUCCEEDED(hr))
{
sink->BeginFigure(m_StartPoint, D2D1_FIGURE_BEGIN_FILLED);
sink->AddArc(m_ArcSegment);
sink->EndFigure(m_ShapeEnding);
sink->Close();
hr = path.CopyTo(m_Shape.GetAddressOf());
if (SUCCEEDED(hr)) return;
}
}
LogErrorF(L"Could not create arc object. X1=%i, Y1=%i, X2=%i, Y2=%i, XRadius=%i, YRadius=%i, Angle=%i",
(int)x1, (int)y1, (int)x2, (int)y2, (int)xRadius, (int)yRadius, (int)angle);
}
示例15: createIB
bool createIB(const Microsoft::WRL::ComPtr<ID3D11Device> &pDevice)
{
unsigned int pIndices[] =
{
0, 1, 2, 2, 3, 0,
4, 5, 6, 6, 7, 4,
8, 9, 10, 10, 11, 8,
12, 13, 14, 14, 15, 12,
16, 17, 18, 18, 19, 16,
20, 21, 22, 22, 23, 20,
};
unsigned int isize = sizeof(pIndices);
m_indices = isize / sizeof(pIndices[0]);
D3D11_BUFFER_DESC idesc;
ZeroMemory(&idesc, sizeof(idesc));
idesc.ByteWidth = isize;
idesc.Usage = D3D11_USAGE_DEFAULT;
idesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
idesc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA indexData;
ZeroMemory(&indexData, sizeof(indexData));
indexData.pSysMem = pIndices;
HRESULT hr = pDevice->CreateBuffer(&idesc, &indexData, m_pIndexBuf.GetAddressOf());
if (FAILED(hr)){
return false;
}
return true;
}