Skip to content

Instantly share code, notes, and snippets.

@redmcg
Last active June 17, 2022 09:07
Show Gist options
  • Select an option

  • Save redmcg/5b11d2d18ff29da5d9d4886b2e1699a1 to your computer and use it in GitHub Desktop.

Select an option

Save redmcg/5b11d2d18ff29da5d9d4886b2e1699a1 to your computer and use it in GitHub Desktop.

Revisions

  1. redmcg revised this gist Jun 17, 2022. 1 changed file with 27 additions and 5 deletions.
    32 changes: 27 additions & 5 deletions d3d9Test.cpp
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,28 @@
    #include <d3d9.h>
    #include <stdio.h>

    static BOOL Monitorenumproc(
    HMONITOR hMonitor,
    HDC unnamedParam2,
    LPRECT bounds,
    LPARAM unnamedParam4
    ) {
    MONITORINFOEX mi;
    mi.cbSize = sizeof(mi);
    if(GetMonitorInfo(hMonitor, &mi)) {
    printf("%p: %s\n", hMonitor, mi.szDevice);
    printf("%d, %d, %d, %d\n", bounds->left, bounds->top, bounds->right, bounds->bottom);
    } else {
    printf("GetMonitorInfo failed for %p\n", hMonitor);
    }
    return TRUE;
    }

    int main(int argc, char **argv) {
    HRESULT hr = E_FAIL;
    HMODULE libHandle = NULL;
    UINT m_uD3DAdapterCount = 0;
    HMONITOR *hMonitor = NULL;

    // Manually load the d3d9.dll library.
    libHandle = LoadLibrary("d3d9.dll");
    @@ -30,11 +48,13 @@ int main(int argc, char **argv) {
    printf("Failed\n");
    } else {
    m_uD3DAdapterCount = pD3D->GetAdapterCount();
    hMonitor = (HMONITOR*) calloc(m_uD3DAdapterCount, sizeof(*hMonitor));
    printf("\nD3D9 says you have %d adapter(s):\n", m_uD3DAdapterCount);
    for (UINT i = 0; i < m_uD3DAdapterCount; i++) {
    D3DADAPTER_IDENTIFIER9 id;
    pD3D->GetAdapterIdentifier(i, 0, &id);
    printf(" - %s (%s)\n", id.DeviceName, id.Description);
    HMONITOR mon = pD3D->GetAdapterMonitor(i);
    printf(" - %s (%s) %p\n", id.DeviceName, id.Description, mon);
    }
    pD3D->Release();
    }
    @@ -85,14 +105,16 @@ int main(int argc, char **argv) {

    // If DX reported adapters that m_rgpDisplays doesn't have, dotnet assumes it's due to mode change.
    if (m_uD3DAdapterCount > m_rgpDisplaysCount) {
    printf(
    "DotNet assumes a mode change, which causes issues in rendering, when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n",
    printf("DotNet assumes a mode change, which causes issues in rendering, when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n",
    m_uD3DAdapterCount, m_rgpDisplaysCount);
    printf(
    "See https://github.com/dotnet/wpf/blob/c4e74175da6108104491e1ae64982444d7c8713d/src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp#L1629\n");
    printf("See https://github.com/dotnet/wpf/blob/c4e74175da6108104491e1ae64982444d7c8713d/src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp#L1629\n");
    } else {
    printf("DotNet should be happy\n");
    }

    printf("\nEnumDisplayMonitors:\n");
    BOOL ret = EnumDisplayMonitors(NULL, NULL, Monitorenumproc, NULL);
    if (!ret) printf("EnumDisplayMonitors ret: %d\n", ret);

    return hr;
    }
  2. redmcg revised this gist Feb 17, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions d3d9Test.cpp
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ int main(int argc, char **argv) {
    printf("Failed\n");
    } else {
    m_uD3DAdapterCount = pD3D->GetAdapterCount();
    printf("You have %d adapter(s):\n", m_uD3DAdapterCount);
    printf("\nD3D9 says you have %d adapter(s):\n", m_uD3DAdapterCount);
    for (UINT i = 0; i < m_uD3DAdapterCount; i++) {
    D3DADAPTER_IDENTIFIER9 id;
    pD3D->GetAdapterIdentifier(i, 0, &id);
    @@ -49,7 +49,7 @@ int main(int argc, char **argv) {
    FreeLibrary(libHandle);
    }

    printf("EnumDisplayDevices:\n");
    printf("\nEnumDisplayDevices:\n");
    UINT m_rgpDisplaysCount = 0;
    for (UINT uDevice = 0; true; uDevice++) {
    DISPLAY_DEVICE dd;
    @@ -81,12 +81,12 @@ int main(int argc, char **argv) {
    printf(" (OK)\n");
    }

    printf("EnumDisplayDevices says %d device(s) are OK\n", m_rgpDisplaysCount);
    printf("\nEnumDisplayDevices says %d device(s) are OK\n\n", m_rgpDisplaysCount);

    // If DX reported adapters that m_rgpDisplays doesn't have, dotnet assumes it's due to mode change.
    if (m_uD3DAdapterCount > m_rgpDisplaysCount) {
    printf(
    "DotNet assumes a mode change when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n",
    "DotNet assumes a mode change, which causes issues in rendering, when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n",
    m_uD3DAdapterCount, m_rgpDisplaysCount);
    printf(
    "See https://github.com/dotnet/wpf/blob/c4e74175da6108104491e1ae64982444d7c8713d/src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp#L1629\n");
  3. redmcg revised this gist Feb 17, 2020. 1 changed file with 87 additions and 85 deletions.
    172 changes: 87 additions & 85 deletions d3d9Test.cpp
    Original file line number Diff line number Diff line change
    @@ -4,93 +4,95 @@
    #include <stdio.h>

    int main(int argc, char **argv) {
    HRESULT hr = E_FAIL;
    HMODULE libHandle = NULL;
    UINT m_uD3DAdapterCount = 0;

    // Manually load the d3d9.dll library.
    libHandle = LoadLibrary("d3d9.dll");

    if (libHandle != NULL) {
    // Define a function pointer to the Direct3DCreate9Ex function.
    typedef HRESULT(WINAPI * LPDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex **);

    // Obtain the address of the Direct3DCreate9Ex function.
    LPDIRECT3DCREATE9EX Direct3DCreate9ExPtr = NULL;

    Direct3DCreate9ExPtr =
    (LPDIRECT3DCREATE9EX)GetProcAddress(libHandle, "Direct3DCreate9Ex");

    if (Direct3DCreate9ExPtr != NULL) {
    // Direct3DCreate9Ex is supported.
    hr = S_OK;
    IDirect3D9Ex *pD3D = NULL;
    if (FAILED(hr = Direct3DCreate9ExPtr(D3D_SDK_VERSION, &pD3D))) {
    printf("Failed\n");
    } else {
    m_uD3DAdapterCount = pD3D->GetAdapterCount();
    printf("You have %d adapter(s):\n", m_uD3DAdapterCount);
    for (UINT i = 0; i < m_uD3DAdapterCount; i++) {
    D3DADAPTER_IDENTIFIER9 id;
    pD3D->GetAdapterIdentifier(i, 0, &id);
    printf(" - %s (%s)\n", id.DeviceName, id.Description);
    HRESULT hr = E_FAIL;
    HMODULE libHandle = NULL;
    UINT m_uD3DAdapterCount = 0;

    // Manually load the d3d9.dll library.
    libHandle = LoadLibrary("d3d9.dll");

    if (libHandle != NULL) {
    // Define a function pointer to the Direct3DCreate9Ex function.
    typedef HRESULT
    (WINAPI *LPDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**);

    // Obtain the address of the Direct3DCreate9Ex function.
    LPDIRECT3DCREATE9EX Direct3DCreate9ExPtr = NULL;

    Direct3DCreate9ExPtr = (LPDIRECT3DCREATE9EX) GetProcAddress(libHandle,
    "Direct3DCreate9Ex");

    if (Direct3DCreate9ExPtr != NULL) {
    // Direct3DCreate9Ex is supported.
    hr = S_OK;
    IDirect3D9Ex *pD3D = NULL;
    if (FAILED(hr = Direct3DCreate9ExPtr(D3D_SDK_VERSION, &pD3D))) {
    printf("Failed\n");
    } else {
    m_uD3DAdapterCount = pD3D->GetAdapterCount();
    printf("You have %d adapter(s):\n", m_uD3DAdapterCount);
    for (UINT i = 0; i < m_uD3DAdapterCount; i++) {
    D3DADAPTER_IDENTIFIER9 id;
    pD3D->GetAdapterIdentifier(i, 0, &id);
    printf(" - %s (%s)\n", id.DeviceName, id.Description);
    }
    pD3D->Release();
    }
    } else {
    // Direct3DCreate9Ex is not supported on this
    // operating system.
    hr = ERROR_NOT_SUPPORTED;
    printf("Not supported\n");
    }
    pD3D->Release();
    }

    // Free the library.
    FreeLibrary(libHandle);
    }

    printf("EnumDisplayDevices:\n");
    UINT m_rgpDisplaysCount = 0;
    for (UINT uDevice = 0; true; uDevice++) {
    DISPLAY_DEVICE dd;
    ZeroMemory(&dd, sizeof(dd));
    dd.cb = sizeof(dd);

    if (!EnumDisplayDevices(NULL, uDevice, &dd, 0))
    break; // no more devices

    printf("- %d: %s", uDevice, dd.DeviceName);

    if (!(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
    printf(" (not attached to desktop)\n");
    continue;
    }

    if (dd.StateFlags
    & (DISPLAY_DEVICE_REMOTE | DISPLAY_DEVICE_MIRRORING_DRIVER)) {
    if (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) {
    printf(" (mirroring driver)\n");
    continue; // mirror devices are considered hidden and should
    // be excluded as display. Remembering that a
    // non-local device is present is sufficient for
    // now.
    }
    }

    m_rgpDisplaysCount++;
    printf(" (OK)\n");
    }

    printf("EnumDisplayDevices says %d device(s) are OK\n", m_rgpDisplaysCount);

    // If DX reported adapters that m_rgpDisplays doesn't have, dotnet assumes it's due to mode change.
    if (m_uD3DAdapterCount > m_rgpDisplaysCount) {
    printf(
    "DotNet assumes a mode change when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n",
    m_uD3DAdapterCount, m_rgpDisplaysCount);
    printf(
    "See https://github.com/dotnet/wpf/blob/c4e74175da6108104491e1ae64982444d7c8713d/src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp#L1629\n");
    } else {
    // Direct3DCreate9Ex is not supported on this
    // operating system.
    hr = ERROR_NOT_SUPPORTED;
    printf("Not supported\n");
    printf("DotNet should be happy\n");
    }

    // Free the library.
    FreeLibrary(libHandle);
    }

    printf("EnumDisplayDevices:\n");
    UINT m_rgpDisplaysCount = 0;
    for (UINT uDevice = 0; true; uDevice++)
    {
    DISPLAY_DEVICE dd;
    ZeroMemory(&dd, sizeof(dd));
    dd.cb = sizeof(dd);

    if (!EnumDisplayDevices(NULL, uDevice, &dd, 0))
    break; // no more devices

    printf("- %d: %s", uDevice, dd.DeviceName);

    if (!(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
    printf(" (not attached to desktop)\n");
    continue;
    }

    if (dd.StateFlags & (DISPLAY_DEVICE_REMOTE | DISPLAY_DEVICE_MIRRORING_DRIVER))
    {
    if (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)
    {
    printf(" (mirroring driver)\n");
    continue; // mirror devices are considered hidden and should
    // be excluded as display. Remembering that a
    // non-local device is present is sufficient for
    // now.
    }
    }

    m_rgpDisplaysCount++;
    printf(" (OK)\n");
    }

    printf("EnumDisplayDevices says %d device(s) are OK\n", m_rgpDisplaysCount);

    // If DX reported adapters that m_rgpDisplays doesn't have, dotnet assumes it's due to mode change.
    if (m_uD3DAdapterCount > m_rgpDisplaysCount) {
    printf("DotNet assumes a mode change when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n", m_uD3DAdapterCount, m_rgpDisplaysCount);
    printf("See https://github.com/dotnet/wpf/blob/c4e74175da6108104491e1ae64982444d7c8713d/src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp#L1629\n");
    } else {
    printf("DotNet should be happy\n");
    }

    return hr;
    return hr;
    }
  4. redmcg revised this gist Feb 17, 2020. 1 changed file with 48 additions and 3 deletions.
    51 changes: 48 additions & 3 deletions d3d9Test.cpp
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@
    int main(int argc, char **argv) {
    HRESULT hr = E_FAIL;
    HMODULE libHandle = NULL;
    UINT m_uD3DAdapterCount = 0;

    // Manually load the d3d9.dll library.
    libHandle = LoadLibrary("d3d9.dll");
    @@ -27,9 +28,9 @@ int main(int argc, char **argv) {
    if (FAILED(hr = Direct3DCreate9ExPtr(D3D_SDK_VERSION, &pD3D))) {
    printf("Failed\n");
    } else {
    UINT adapterCount = pD3D->GetAdapterCount();
    printf("You have %d adapter(s):\n", adapterCount);
    for (UINT i = 0; i < adapterCount; i++) {
    m_uD3DAdapterCount = pD3D->GetAdapterCount();
    printf("You have %d adapter(s):\n", m_uD3DAdapterCount);
    for (UINT i = 0; i < m_uD3DAdapterCount; i++) {
    D3DADAPTER_IDENTIFIER9 id;
    pD3D->GetAdapterIdentifier(i, 0, &id);
    printf(" - %s (%s)\n", id.DeviceName, id.Description);
    @@ -47,5 +48,49 @@ int main(int argc, char **argv) {
    FreeLibrary(libHandle);
    }

    printf("EnumDisplayDevices:\n");
    UINT m_rgpDisplaysCount = 0;
    for (UINT uDevice = 0; true; uDevice++)
    {
    DISPLAY_DEVICE dd;
    ZeroMemory(&dd, sizeof(dd));
    dd.cb = sizeof(dd);

    if (!EnumDisplayDevices(NULL, uDevice, &dd, 0))
    break; // no more devices

    printf("- %d: %s", uDevice, dd.DeviceName);

    if (!(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
    printf(" (not attached to desktop)\n");
    continue;
    }

    if (dd.StateFlags & (DISPLAY_DEVICE_REMOTE | DISPLAY_DEVICE_MIRRORING_DRIVER))
    {
    if (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)
    {
    printf(" (mirroring driver)\n");
    continue; // mirror devices are considered hidden and should
    // be excluded as display. Remembering that a
    // non-local device is present is sufficient for
    // now.
    }
    }

    m_rgpDisplaysCount++;
    printf(" (OK)\n");
    }

    printf("EnumDisplayDevices says %d device(s) are OK\n", m_rgpDisplaysCount);

    // If DX reported adapters that m_rgpDisplays doesn't have, dotnet assumes it's due to mode change.
    if (m_uD3DAdapterCount > m_rgpDisplaysCount) {
    printf("DotNet assumes a mode change when m_uD3DAdapterCount > m_rgpDisplaysCount (%d > %d)\n", m_uD3DAdapterCount, m_rgpDisplaysCount);
    printf("See https://github.com/dotnet/wpf/blob/c4e74175da6108104491e1ae64982444d7c8713d/src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp#L1629\n");
    } else {
    printf("DotNet should be happy\n");
    }

    return hr;
    }
  5. redmcg revised this gist Feb 13, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion d3d9Test.cpp
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ int main(int argc, char **argv) {
    pD3D->GetAdapterIdentifier(i, 0, &id);
    printf(" - %s (%s)\n", id.DeviceName, id.Description);
    }
    pD3D->Release();
    }
    } else {
    // Direct3DCreate9Ex is not supported on this
    @@ -47,4 +48,4 @@ int main(int argc, char **argv) {
    }

    return hr;
    }
    }
  6. redmcg created this gist Feb 13, 2020.
    50 changes: 50 additions & 0 deletions d3d9Test.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    // compile with: x86_64-w64-mingw32-g++ d3d9Test.cpp

    #include <d3d9.h>
    #include <stdio.h>

    int main(int argc, char **argv) {
    HRESULT hr = E_FAIL;
    HMODULE libHandle = NULL;

    // Manually load the d3d9.dll library.
    libHandle = LoadLibrary("d3d9.dll");

    if (libHandle != NULL) {
    // Define a function pointer to the Direct3DCreate9Ex function.
    typedef HRESULT(WINAPI * LPDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex **);

    // Obtain the address of the Direct3DCreate9Ex function.
    LPDIRECT3DCREATE9EX Direct3DCreate9ExPtr = NULL;

    Direct3DCreate9ExPtr =
    (LPDIRECT3DCREATE9EX)GetProcAddress(libHandle, "Direct3DCreate9Ex");

    if (Direct3DCreate9ExPtr != NULL) {
    // Direct3DCreate9Ex is supported.
    hr = S_OK;
    IDirect3D9Ex *pD3D = NULL;
    if (FAILED(hr = Direct3DCreate9ExPtr(D3D_SDK_VERSION, &pD3D))) {
    printf("Failed\n");
    } else {
    UINT adapterCount = pD3D->GetAdapterCount();
    printf("You have %d adapter(s):\n", adapterCount);
    for (UINT i = 0; i < adapterCount; i++) {
    D3DADAPTER_IDENTIFIER9 id;
    pD3D->GetAdapterIdentifier(i, 0, &id);
    printf(" - %s (%s)\n", id.DeviceName, id.Description);
    }
    }
    } else {
    // Direct3DCreate9Ex is not supported on this
    // operating system.
    hr = ERROR_NOT_SUPPORTED;
    printf("Not supported\n");
    }

    // Free the library.
    FreeLibrary(libHandle);
    }

    return hr;
    }