Microsoft Windows CE 3.0  

Finding a Surface with a Device Context

This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

You can retrieve a pointer to a surface's IDirectDrawSurface5interface from the device context for the surface by calling the IDirectDraw4::GetSurfaceFromDCmethod. This feature might be very useful for component applications or ActiveX controls, that are commonly given a device context to draw into at run-time, but could benefit by exploiting the features exposed by the IDirectDrawSurface5interface.

A device context might identify memory that isn't associated with a DirectDraw object, or the device context might identify a surface for another DirectDraw object entirely. The latter case is most likely to occur on a system with multiple monitors. If the device context doesn't identify a surface that wasn't created by that DirectDraw object, the method fails, returning DDERR_NOTFOUND.

The following sample code shows what a very simple scenario might look like:

// For this example, the hdc variable is a valid
// handle to a video memory device context, and the // lpDD4
variable is a valid IDirectDraw4 interface pointer.
lpDD4->GetSurfaceFromDC(hdc, &lpDDS4); if(SUCCEEDED(hr)) {
// Use the surface interface. } else if(DDERR_NOTFOUND == hr) {
OutputDebugString("HDC not from this DirectDraw surface\n");

 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.