Use the DirectDrawEnumerateEx function to enumerate devices on systems with multiple monitors, specifying flags to determine what types of DirectDraw devices should be enumerated. The function calls an application-defined DDEnumCallbackEx function for each enumerated device.
The DirectDrawEnumerateEx function is supported on Windows 98 and Windows NT 5.0 (and newer) operating systems, and can only be called by retrieving the function's address from the dynamic-link library. To do this at run-time, load the function's address from the Ddraw.dll dynamic link library by calling the GetProcAddress Win32 function. The following example shows one way you can do this:
HINSTANCE h = LoadLibrary("ddraw.dll");
// If ddraw.dll doesn't exist in the search path,
// then DirectX probably isn't installed, so fail.
if (!h)
return FALSE;
// Note that you must know which version of the
// function to retrieve (see the following text).
// For this example, we use the ANSI version.
LPDIRECTDRAWENUMERATEEX lpDDEnumEx;
lpDDEnumEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(h,"DirectDrawEnumerateExA");
// If the function is there, call it to enumerate all display
// devices attached to the desktop, and any non-display DirectDraw
// devices.
if (lpDDEnumEx)
lpDDEnumEx(Callback, NULL,
DDENUM_ATTACHEDSECONDARYDEVICES |
DDENUM_NONDISPLAYDEVICES
);
else
{
/*
* We must be running on an old version of ddraw. Therefore,
* by definiton, multimon isn't supported. Fall back on
* DirectDrawEnumerate to enumerate standard devices on a
* single monitor system.
*/
DirectDrawEnumerate(OldCallback,NULL);
/* Note that it could be handy to let the OldCallback function
* be a wrapper for a DDEnumCallbackEx.
*
* Such a function would look like:
* BOOL FAR PASCAL OldCallback(GUID FAR *lpGUID,
* LPSTR pName,
* LPSTR pDesc,
* LPVOID pContext)
* {
* return Callback(lpGUID,pName,pDesc,pContext,NULL);
* }
*/
}
// If the library was loaded by calling LoadLibrary(),
// then you must use FreeLibrary() to let go of it.
FreeLibrary(h);
The previous example will work for applications that link to Ddraw.dll at run-time or load-time.
Note that you must retrieve the address of either the ANSI or Unicode version of the DirectDrawEnumerateEx function, depending of the type of strings your application uses. When declaring the corresponding callback function, use the LPTSTR data type for the string parameters. The LPTSTR data type compiles to use Unicode strings if you declare the _UNICODE symbol, and ANSI strings otherwise. By using the LPTSTR data type, the function should link properly regardless of the string type you use in your application.