ReactOS 0.4.15-dev-7788-g1ad9096
GetDeviceIdentifier.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS DirectX
4 * FILE: dll/directx/ddraw/Ddraw/GetDeviceIdentifier.c
5 * PURPOSE: IDirectDraw7 Implementation
6 * PROGRAMMER: Magnus Olsen
7 *
8 */
9
10/* TODO
11 * We need adding digital signature detections for the drivers
12 * and count out which level the signtature driver got, the value
13 * shall be save to pDDDI->dwWHQLLevel, But I do not known how todo
14 * this part yet, That is only missing feature in this functions
15 *
16 * Write a UML digram for this api
17 */
18
19#include "rosdraw.h"
20
21#include <string.h>
22
23/* For DirectDraw 4 - 6 */
27{
28 HRESULT retVal = DD_OK;
30
31 ZeroMemory(&pDDDI2,sizeof(DDDEVICEIDENTIFIER2));
32
34 {
35 memcpy(&pDDDI2 , pDDDI, sizeof(DDDEVICEIDENTIFIER));
36
38
39 if (IsBadWritePtr(pDDDI, sizeof(DDDEVICEIDENTIFIER)))
40 {
41 retVal = DDERR_INVALIDPARAMS;
42 }
43 else
44 {
45 memcpy(pDDDI , &pDDDI2, sizeof(DDDEVICEIDENTIFIER) );
46 }
47 }
49 {
50 retVal = DD_FALSE;
51 }
53
54 return retVal;
55}
56
60{
62
63 BOOL found = FALSE;
64 DWORD iDevNum = 0;
65 DISPLAY_DEVICEA DisplayDeviceA;
66 HKEY hKey;
67 DWORD lpType = 0;
69 char *pdest;
70 char* pcCnvEnd;
71 long *lpdata;
72
74
76
78 {
79 if ( (IsBadWritePtr( pDDDI, sizeof(DDDEVICEIDENTIFIER2) ) ) ||
81 {
82 retVal = DDERR_INVALIDPARAMS;
84 }
85
86 /* now we can start getting the driver data */
87
88 while (1)
89 {
90 ZeroMemory(&DisplayDeviceA,sizeof(DISPLAY_DEVICEA));
91
92 DisplayDeviceA.cb = sizeof(DISPLAY_DEVICEA);
93
94 if ( EnumDisplayDevicesA( NULL, iDevNum, &DisplayDeviceA, 0) == 0)
95 {
96 retVal = DDERR_INVALIDPARAMS;
97 break;
98 }
99
100 if (_stricmp(DisplayDeviceA.DeviceName, This->lpLcl->lpGbl->cDriverName) != 0)
101 {
102 /* if we got another device like hardware mpeg decoder or video card or another drv */
103 found = TRUE;
104 }
105 else if (DisplayDeviceA.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
106 {
107 /* double check if it primary driver we just found */
108 if (!_stricmp( This->lpLcl->lpGbl->cDriverName, "DISPLAY"))
109 {
110 /* yeah we found it */
111 found = TRUE;
112 }
113 }
114
115 if (found != FALSE)
116 {
117 /* we found our driver now we start setup it */
118 if (!_strnicmp(DisplayDeviceA.DeviceKey,"\\REGISTRY\\Machine\\",18))
119 {
121 {
122
123 if (RegQueryValueExA(hKey, "InstalledDisplayDrivers",0, &lpType, (LPBYTE)pDDDI->szDriver, &strSize) != ERROR_SUCCESS)
124 {
126 }
127 else
128 {
129 strcat(pDDDI->szDriver,".dll");
130 }
132 }
133
134 strcpy( pDDDI->szDescription, DisplayDeviceA.DeviceString);
135 pDDDI->liDriverVersion.HighPart = 0;
136 pDDDI->liDriverVersion.LowPart = 0;
137
138 pdest = strstr(DisplayDeviceA.DeviceID,"REV_");
139 pDDDI->dwRevision = strtol ( &pdest[4], &pcCnvEnd, 16);
140
141 pdest = strstr(DisplayDeviceA.DeviceID,"SUBSYS_");
142 pDDDI->dwSubSysId = strtol ( &pdest[7], &pcCnvEnd, 16);
143
144 pdest = strstr(DisplayDeviceA.DeviceID,"DEV_");
145 pDDDI->dwDeviceId = strtol ( &pdest[4], &pcCnvEnd, 16);
146
147 pdest = strstr(DisplayDeviceA.DeviceID,"VEN_");
148 pDDDI->dwVendorId =strtol ( &pdest[4], &pcCnvEnd, 16);
149
150 /* Count out the guidDeviceIdentifier */
151 memcpy(&pDDDI->guidDeviceIdentifier, &CLSID_DirectDraw,sizeof(GUID));
152
153 pDDDI->guidDeviceIdentifier.Data1 ^= pDDDI->dwVendorId;
154
155 lpdata = (long *)&pDDDI->guidDeviceIdentifier.Data2;
156 *lpdata ^= pDDDI->dwDeviceId;
157
158 lpdata = (long *)&pDDDI->guidDeviceIdentifier.Data4;
159 *lpdata = (*lpdata ^ pDDDI->dwSubSysId) ^ pDDDI->liDriverVersion.LowPart;
160
161 lpdata = (long *)&pDDDI->guidDeviceIdentifier.Data4[4];
162 *lpdata = (*lpdata ^ pDDDI->dwRevision) ^ pDDDI->liDriverVersion.HighPart;
163
164 /* FIXME pDDDI->dwWHQLLevel
165 * we leave this with no informations, I do not known
166 * if program care for it, I mark this api done, and
167 * tested, no bugs was found in it
168 */
169 pDDDI->dwWHQLLevel = 0;
170 retVal = DD_OK;
171 }
172
173 break;
174 }
175
176 iDevNum++;
177 }
178
179 }
181 {
182 retVal = DD_FALSE;
183 }
184 _SEH2_END;
185
187 return retVal;
188}
HRESULT WINAPI Main_DirectDraw_GetDeviceIdentifier(LPDDRAWI_DIRECTDRAW_INT This, LPDDDEVICEIDENTIFIER pDDDI, DWORD dwFlags)
HRESULT WINAPI Main_DirectDraw_GetDeviceIdentifier7(LPDDRAWI_DIRECTDRAW_INT This, LPDDDEVICEIDENTIFIER2 pDDDI, DWORD dwFlags)
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define RegCloseKey(hKey)
Definition: registry.h:49
#define _stricmp
Definition: cat.c:22
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
CRITICAL_SECTION ddcs
Definition: main.c:14
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3327
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4038
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define _SEH2_LEAVE
Definition: filesup.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
#define DDGDI_GETHOSTIDENTIFIER
Definition: ddraw.h:202
#define DD_OK
Definition: ddraw.h:186
#define MAX_DDDEVICEID_STRING
Definition: ddraw.h:201
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
#define DD_FALSE
Definition: ddraw.h:187
DWORD StateFlags
Definition: wingdi.h:2812
CHAR DeviceString[128]
Definition: wingdi.h:2811
CHAR DeviceName[32]
Definition: wingdi.h:2810
CHAR DeviceID[128]
Definition: wingdi.h:2813
CHAR DeviceKey[128]
Definition: wingdi.h:2814
char szDescription[MAX_DDDEVICEID_STRING]
Definition: ddraw.h:1346
char szDriver[MAX_DDDEVICEID_STRING]
Definition: ddraw.h:1345
unsigned char * LPBYTE
Definition: typedefs.h:53
BOOL WINAPI EnumDisplayDevicesA(LPCSTR lpDevice, DWORD iDevNum, PDISPLAY_DEVICEA lpDisplayDevice, DWORD dwFlags)
Definition: display.c:23
#define ZeroMemory
Definition: winbase.h:1712
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
#define DISPLAY_DEVICE_PRIMARY_DEVICE
Definition: wingdi.h:1398
struct _DISPLAY_DEVICEA DISPLAY_DEVICEA
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12