1
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 3, 2018 at 18:33
  • \$\begingroup\$ From the ddraw.h header I am using: #ifndef DIRECTDRAW_VERSION #define DIRECTDRAW_VERSION 0x0700 #endif /* DIRECTDRAW_VERSION */ \$\endgroup\$
    – DHarding
    Commented Jul 5, 2018 at 7:30
  • \$\begingroup\$ 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. \$\endgroup\$
    – DHarding
    Commented Jul 7, 2018 at 18:37
  • \$\begingroup\$ Have you tried getting rid of DDCREATE_EMULATIONONLY? \$\endgroup\$ Commented Jul 8, 2018 at 7:41
  • \$\begingroup\$ 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. \$\endgroup\$
    – DHarding
    Commented Jul 14, 2018 at 16:03

2 Answers 2

0
\$\begingroup\$

Another possible cause is that the old sample apps and the SDK's themselves used ANSI 8 bits 'char' as their character sets and x32 as the apps bitness.

Come to this era and the default is always Unicode and invariably x64.

It pays to 'OutputDebugString' and see the text that is used to set the DX structures, the character set settings could be the problem.

\$\endgroup\$
3
  • \$\begingroup\$ As a matter of fact I have been going back to to the sample applications that came with DirectX 6.1 and I can compile them perfectly, after some twinkling of course. \$\endgroup\$ Commented Aug 8, 2022 at 6:02
  • \$\begingroup\$ Welcome to GDSE. I don't see anything in the question or the documentation for SetDisplayMode that has anything to do with character sets. \$\endgroup\$
    – Pikalek
    Commented Aug 15, 2022 at 0:52
  • \$\begingroup\$ As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. \$\endgroup\$
    – Community Bot
    Commented Aug 15, 2022 at 0:55
0
\$\begingroup\$

The below method works fine to initialize the Video 1024x768x32.

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);
        }   
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$
    – DHarding
    Commented Feb 1, 2021 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .