# Why is my call to SetDisplayMode not supported?

I have some legacy DirectX code that always returns DDERR_UNSUPPORTED.

I originally developed the code using DirectX3, and I am porting it to DirectX7 after spending years away from programming.

The following line is returning DDERR_UNSUPPORTED rather than DD_OK:

hrRetVal = pDDraw->SetDisplayMode(dwWidth, dwHeight, dwBPP, 0, 0);


Could someone please take a quick peek and respond if you see why this might be the case? This is not a commercial application... just something to do for fun.

Based on the Microsoft on-line documents, the SetDisplayMode method is not deprecated, and should work. A compiled version of my legacy program written with DirectX3 renders graphics on newer OS's such as Windows 10, without issue. I am interested in making some changes.

This Video compilation unit:

• Sets the video mode to 1024 X 768
• Create a DirectX instance, set the cooperative level.
• Which when destroyed will Restore video to original mode, and flip to GDI

void Video::Initialize(void)
{

TRACE("Video::Initialize invoked\n");

hrRetVal = {0};
DWORD dwDefaultRefreshRate = 0x0;
DWORD  dwWidth = 1024, dwHeight = 768, dwBPP = 8, dwRefreshRate = dwDefaultRefreshRate, dwFlags = 0x0;

try
{
Check(hrRetVal); // check for DD_OK

TRACE("Video: using emulation mode, no hardware\n"); // debugging
TRACE("Video: DirectDrawCreateEx invoked\n");
hrRetVal = DirectDrawCreateEx((GUID*)DDCREATE_EMULATIONONLY, (LPVOID*)&pDDraw, IID_IDirectDraw7, NULL);

Check(hrRetVal); // TRACE value of hrRetVal
if (DD_OK == hrRetVal)
{
TRACE("Video SetCooperativeLevel invoked\n");
hrRetVal = pDDraw->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
Check(hrRetVal);
if (DD_OK == hrRetVal)
{

// Lets see if the video is supported
hrRetVal = QueryVideoCapability();
Check(hrRetVal);

if (DD_OK == hrRetVal)
{

TRACE("Attempting to set video resolution to: %d %d \n", dwWidth, dwHeight);

hrRetVal = pDDraw->SetDisplayMode(dwWidth, dwHeight, dwBPP, 0, 0); // this line always returns DDERR_UNSUPPORTED

// hrRetVal == DDERR_UNSUPPORTED after call to SetDisplayMode

Check(hrRetVal);
if (DD_OK != hrRetVal)
throw (VIDEO_EXCEPTION); // with throw an exception since hrRetVal == DDERR_UNSUPPORTED
}
}
else
{
Check(hrRetVal);
throw (VIDEO_EXCEPTION);
}
}
else
{
Check(hrRetVal);
throw (VIDEO_EXCEPTION);
}
}

catch(int exception)
{
TRACE("%Xh exception caught by Video::Initialize\n", exception);
Video::Check(hrRetVal);

if (exception == VIDEO_EXCEPTION)
{
char message[80];
strcpy_s ( message, "Unable to initialize video. ");
strcat_s ( message, "\nApplication will now terminate.");
FatalMessageBox( message );

TRACE("APP_EXCEPTION thrown by Video::Initialize\n");
throw (APP_EXCEPTION);
}
}
}


I'm using Visual Studio 2017 Pro v15.7.2, on Windows 10 Build 1803.

• FWIW, all of DirectDraw has been deprecated since DirectX 8. That said, DirectDraw7 is available to x64 native processes so it's "less deprecated' than say DirectPlay which is not even included in the OS unless you download an optional feature. – Chuck Walbourn Jul 3 '18 at 18:33
• From the ddraw.h header I am using: #ifndef DIRECTDRAW_VERSION #define DIRECTDRAW_VERSION 0x0700 #endif /* DIRECTDRAW_VERSION */ – DHarding Jul 5 '18 at 7:30
• in the VS 2017 debugger pDDraw->SetDisplayMode(...) returns E_NOTIMPL Not implemented. This is true if pDDraw is of type LPDIRECTDRAW or IDirectDraw7. FWIW my legacy exe written in DirectX 3 runs fine untouched, it does not throw any exception and terminate. The same code recompiled to use DirectDraw3 or DirectDraw7 does not work because SetDisplayMode does not returning DD_OK. – DHarding Jul 7 '18 at 18:37
• Have you tried getting rid of DDCREATE_EMULATIONONLY? – Chuck Walbourn Jul 8 '18 at 7:41
• Thank you Chuck. I apologize for the slow response. Yes I have tried that. Next steps are for me to write a very simple sample application, for illustration, which I would like to share. Currently I am using abstract data types, such as video, joystick, sound, sprite, background, application etc. Which is class library for utilizing directx. I wrote this back in 1997 when directx was relatively new, and MSJ was still in print. With my schedule it will take me some time to put the sample together. If there was a place to upload the project for others to look at I would be happy to do so. – DHarding Jul 14 '18 at 16:03

I am answering my own question.

I did not find the code to be deprecated. If you install the "DirectX Control Panel" you can see what video modes are supported.

void Video::Initialize(void)
{

TRACE("Video::Initialize invoked\n");

try
{
hrRetVal = DirectDrawCreateEx(NULL, (LPVOID*) &pDDraw, IID_IDirectDraw7, NULL);

if (DD_OK == hrRetVal)
{

hrRetVal = pDDraw->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);

if (DD_OK == hrRetVal)
{
// Lets see if the video is supported
hrRetVal = QueryVideoCapability();
if (DD_OK != hrRetVal)
{
Check(hrRetVal);
}

hrRetVal = pDDraw->SetDisplayMode(1024, 768, 32, 0, DDSDM_STANDARDVGAMODE);
if (DD_OK != hrRetVal)
throw (VIDEO_EXCEPTION);
}
else
throw (VIDEO_EXCEPTION);
}
else
throw (VIDEO_EXCEPTION);
}

catch(int exception)
{

TRACE("%Xh exception caught by Video::Initialize\n", exception);
Video::Check(hrRetVal);

if (exception == VIDEO_EXCEPTION)
{
char message[80];
strcpy_s ( message, "Unable to initialize video. ");
strcat_s ( message, "\nApplication will now terminate.");
FatalMessageBox( message );

TRACE("APP_EXCEPTION thrown by Video::Initialize\n");
throw (APP_EXCEPTION);
}
}
}
$$$$
`
• I am using the following line of code which works: hrRetVal = pDDraw->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, BPP, Hz, NOT_IMPLEMENTED); I found that BPP must equal 32, and I am able to use full screen (Windows 10) mode in DirectX 7.0 not running in a window – DHarding Feb 1 at 10:36

Possible reason: The DirectDraw in fullscreen mode is not supported on Windows 10.