Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreDDDriverList.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreD3D7RenderSystem.h"
    00026 #include "OgreDDDriverList.h"
    00027 #include "OgreDDDriver.h"
    00028 #include "OgreLogManager.h"
    00029 #include "OgreException.h"
    00030
    00031 namespace Ogre {
    00032
    00033     // Non-member callback functions
    00034     static BOOL WINAPI DDEnumCallbackEx(GUID FAR *lpGUID,
    00035                     LPSTR     lpDriverDescription,
    00036                     LPSTR     lpDriverName,
    00037                     LPVOID    lpContext,
    00038                     HMONITOR  hm)
    00039     {
    00040
    00041         DDDriverList* driverList;
    00042
    00043         // Use context pointer to add this new object to the list
    00044         driverList = (DDDriverList*)lpContext;
    00045         driverList->AddDriver(lpGUID, lpDriverDescription, lpDriverName);
    00046
    00047
    00048         // Continue enumeration (to find other cards)
    00049         return TRUE;
    00050     }
    00051
    00052     static BOOL WINAPI DDEnumCallback(GUID FAR *lpGUID,
    00053                                LPSTR  lpDriverDescription,
    00054                                LPSTR  lpDriverName,
    00055                                LPVOID lpContext)
    00056     {
    00057         return DDEnumCallbackEx(lpGUID,lpDriverDescription,lpDriverName,lpContext,NULL);
    00058     }
    00059
    00060     DDDriverList::DDDriverList()
    00061     {
    00062         // Default constructor
    00063         // Will create a  new driver list and enumerate it
    00064
    00065         // Enumerate the list
    00066         enumerate();
    00067
    00068     }
    00069
    00070     DDDriverList::~DDDriverList()
    00071     {
    00072         for(size_t i=0; i<count(); i++)
    00073         {
    00074             item(i)->Cleanup();
    00075         }
    00076         // Release drivers
    00077         mDriverList.clear();
    00078     }
    00079
    00080     BOOL DDDriverList::enumerate()
    00081     {
    00082
    00083         LPDIRECTDRAWENUMERATEEX lpDDEnumEx;
    00084         HINSTANCE h;
    00085
    00086         LogManager::getSingleton().logMessage("----- DirectDraw Detection Starts");
    00087
    00088         h = LoadLibrary("ddraw.dll");
    00089
    00090         // If ddraw.dll doesn't exist in the search path,
    00091         // then DirectX probably isn't installed, so fail.
    00092         if (!h)
    00093             throw Exception(0, "Error loading ddraw.dll", "DDDriverList - enumerate");
    00094
    00095         // Note that you must know which version of the
    00096         // function to retrieve (see the following text).
    00097         // For this example, we use the ANSI version.
    00098         lpDDEnumEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(h,"DirectDrawEnumerateExA");
    00099          // If the function is there, call it to enumerate all display
    00100         // devices attached to the desktop, and any non-display DirectDraw
    00101         // devices.
    00102         if (lpDDEnumEx)
    00103             lpDDEnumEx(DDEnumCallbackEx, this,
    00104                 DDENUM_ATTACHEDSECONDARYDEVICES |
    00105                 DDENUM_NONDISPLAYDEVICES             );
    00106         else
    00107         {
    00108             /*
    00109              * We must be running on an old version of DirectDraw.
    00110              * Therefore MultiMon isn't supported. Fall back on
    00111              * DirectDrawEnumerate to enumerate standard devices on a
    00112              * single-monitor system.
    00113             */
    00114             DirectDrawEnumerate(DDEnumCallback,this);
    00115
    00116         }
    00117         // If the library was loaded by calling LoadLibrary(),
    00118         // then you must use FreeLibrary() to let go of it.
    00119
    00120         FreeLibrary(h);
    00121
    00122         LogManager::getSingleton().logMessage("----- DirectDraw Detection Ends");
    00123
    00124         return TRUE;
    00125     }
    00126
    00127     void DDDriverList::AddDriver(
    00128         GUID FAR *lpGuid,
    00129         LPSTR lpDriverDesc,
    00130         LPSTR lpDriverName )
    00131     {
    00132         mDriverList.push_back( DDDriver(lpGuid, lpDriverDesc, lpDriverName) );
    00133
    00134         LogManager::getSingleton().logMessage( LML_NORMAL, "Detected DirectDraw driver %s.\n", lpDriverDesc );
    00135     }
    00136
    00137     size_t DDDriverList::count(void) const
    00138     {
    00139         return mDriverList.size();
    00140     }
    00141
    00142     DDDriver* DDDriverList::item(size_t index)
    00143     {
    00144         return &mDriverList.at( index );
    00145     }
    00146 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:22 2004