Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Added DxDiagOutput and DxDiagReport samples
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Mar 2, 2021
1 parent 0514bd6 commit 009dbef
Show file tree
Hide file tree
Showing 23 changed files with 5,821 additions and 0 deletions.
172 changes: 172 additions & 0 deletions DxDiag/DxDiagOutput/DxDiagOutput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//----------------------------------------------------------------------------
// File: DxDiagOutput.cpp
//
// Desc: Sample app to read info from dxdiagn.dll by enumeration
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License (MIT).
//-----------------------------------------------------------------------------
#define INITGUID
#include <Windows.h>
#include <stdio.h>
#include <assert.h>
#include <initguid.h>
#include <dxdiag.h>

#include <wrl/client.h>

using Microsoft::WRL::ComPtr;


//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT PrintContainerAndChildren(WCHAR* wszParentName, IDxDiagContainer* pDxDiagContainer);




//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application. We use just the console window
//-----------------------------------------------------------------------------
int main()
{
HRESULT hr = CoInitialize(nullptr);
if (FAILED(hr))
return 1;

// CoCreate a IDxDiagProvider*
ComPtr<IDxDiagProvider> pDxDiagProvider;
hr = CoCreateInstance(CLSID_DxDiagProvider,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IDxDiagProvider,
(LPVOID*)&pDxDiagProvider);
if (FAILED(hr))
return 1;

// Fill out a DXDIAG_INIT_PARAMS struct and pass it to IDxDiagContainer::Initialize
// Passing in TRUE for bAllowWHQLChecks, allows dxdiag to check if drivers are
// digital signed as logo'd by WHQL which may connect via internet to update
// WHQL certificates.
DXDIAG_INIT_PARAMS dxDiagInitParam = {};
dxDiagInitParam.dwSize = sizeof(DXDIAG_INIT_PARAMS);
dxDiagInitParam.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION;
dxDiagInitParam.bAllowWHQLChecks = TRUE;
dxDiagInitParam.pReserved = nullptr;

hr = pDxDiagProvider->Initialize(&dxDiagInitParam);
if (FAILED(hr))
return 1;

ComPtr<IDxDiagContainer> pDxDiagRoot;
hr = pDxDiagProvider->GetRootContainer(&pDxDiagRoot);
if (FAILED(hr))
return 1;

// This function will recursivly print the properties
// the root node and all its child.
hr = PrintContainerAndChildren(nullptr, pDxDiagRoot.Get());
if (FAILED(hr))
return 1;

CoUninitialize();

return 0;
}




//-----------------------------------------------------------------------------
// Name: PrintContainerAndChildren()
// Desc: Recursivly print the properties the root node and all its child
// to the console window
//-----------------------------------------------------------------------------
HRESULT PrintContainerAndChildren(WCHAR* wszParentName, IDxDiagContainer* pDxDiagContainer)
{
HRESULT hr;

DWORD dwPropCount;
DWORD dwPropIndex;
WCHAR wszPropName[512];
VARIANT var;
WCHAR wszPropValue[512];

DWORD dwChildCount;
DWORD dwChildIndex;
WCHAR wszChildName[512];
ComPtr<IDxDiagContainer> pChildContainer;

VariantInit(&var);

hr = pDxDiagContainer->GetNumberOfProps(&dwPropCount);
if (SUCCEEDED(hr))
{
// Print each property in this container
for (dwPropIndex = 0; dwPropIndex < dwPropCount; dwPropIndex++)
{
hr = pDxDiagContainer->EnumPropNames(dwPropIndex, wszPropName, 512);
if (SUCCEEDED(hr))
{
hr = pDxDiagContainer->GetProp(wszPropName, &var);
if (SUCCEEDED(hr))
{
// Switch off the type. There's 4 different types:
switch (var.vt)
{
case VT_UI4:
swprintf_s(wszPropValue, 512, L"%d", var.ulVal);
break;
case VT_I4:
swprintf_s(wszPropValue, 512, L"%d", var.lVal);
break;
case VT_BOOL:
wcscpy_s(wszPropValue, 512, (var.boolVal) ? L"true" : L"false");
break;
case VT_BSTR:
wcscpy_s(wszPropValue, 512, var.bstrVal);
break;
}

// Add the parent name to the front if there's one, so that
// its easier to read on the screen
if (wszParentName)
wprintf(L"%ls.%ls = %ls\n", wszParentName, wszPropName, wszPropValue);
else
wprintf(L"%ls = %ls\n", wszPropName, wszPropValue);

// Clear the variant (this is needed to free BSTR memory)
VariantClear(&var);
}
}
}
}

// Recursivly call this function for each of its child containers
hr = pDxDiagContainer->GetNumberOfChildContainers(&dwChildCount);
if (SUCCEEDED(hr))
{
for (dwChildIndex = 0; dwChildIndex < dwChildCount; dwChildIndex++)
{
hr = pDxDiagContainer->EnumChildContainerNames(dwChildIndex, wszChildName, 512);
if (SUCCEEDED(hr))
{
hr = pDxDiagContainer->GetChildContainer(wszChildName, &pChildContainer);
if (SUCCEEDED(hr))
{
// wszFullChildName isn't needed but is used for text output
WCHAR wszFullChildName[512];
if (wszParentName)
swprintf_s(wszFullChildName, 512, L"%ls.%ls", wszParentName, wszChildName);
else
wcscpy_s(wszFullChildName, 512, wszChildName);
PrintContainerAndChildren(wszFullChildName, pChildContainer.Get());
}
}
}
}

return S_OK;
}
76 changes: 76 additions & 0 deletions DxDiag/DxDiagOutput/DxDiagOutput.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Microsoft Visual C++ generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define IDC_STATIC -1
#include <WinResRc.h>



/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN_ICON ICON "..\\..\\dxut\\optional\\directx.ico"

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#define IDC_STATIC -1\r\n"
"#include <winresrc.h>\r\n"
"\r\n"
"\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED

#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

31 changes: 31 additions & 0 deletions DxDiag/DxDiagOutput/DxDiagOutput_2019.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio Version 16
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DxDiagOutput", "DxDiagOutput_2019.vcxproj", "{A0763B6A-73EC-42D1-A283-F07D7613AC3C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Profile|Win32 = Profile|Win32
Profile|x64 = Profile|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Debug|Win32.ActiveCfg = Debug|Win32
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Debug|Win32.Build.0 = Debug|Win32
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Debug|x64.ActiveCfg = Debug|x64
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Debug|x64.Build.0 = Debug|x64
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Profile|Win32.ActiveCfg = Profile|Win32
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Profile|Win32.Build.0 = Profile|Win32
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Profile|x64.ActiveCfg = Profile|x64
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Profile|x64.Build.0 = Profile|x64
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Release|Win32.ActiveCfg = Release|Win32
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Release|Win32.Build.0 = Release|Win32
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Release|x64.ActiveCfg = Release|x64
{A0763B6A-73EC-42D1-A283-F07D7613AC3C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading

0 comments on commit 009dbef

Please sign in to comment.