@@ -108,12 +108,13 @@ GdiGetHandleUserData(
108108#define FL_INVERT_COLORS 0x01
109109#define FL_RED_BLUE 0x02
110110
111+ static
111112BOOL
112113InitPerBitDepth (
113114 _In_ ULONG cBitsPerPixel ,
114115 _In_ ULONG cx ,
115116 _In_ ULONG cy ,
116- _Out_ HBITMAP * phbmp ,
117+ _Out_opt_ HBITMAP * phbmpDDB ,
117118 _Out_ HDC * phdcDIB ,
118119 _Out_ HBITMAP * phbmpDIB ,
119120 _Out_ PVOID * ppvBits ,
@@ -126,12 +127,15 @@ InitPerBitDepth(
126127 } bmiBuffer ;
127128 LPBITMAPINFO pbmi = (LPBITMAPINFO )& bmiBuffer ;
128129
129- /* Create a bitmap */
130- * phbmp = CreateBitmap (cx , cy , 1 , cBitsPerPixel , NULL );
131- if (* phbmp == NULL )
130+ if (phbmpDDB != NULL )
132131 {
133- printf ("CreateBitmap failed %lu\n" , cBitsPerPixel );
134- return FALSE;
132+ /* Create a bitmap */
133+ * phbmpDDB = CreateBitmap (cx , cy , 1 , cBitsPerPixel , NULL );
134+ if (* phbmpDDB == NULL )
135+ {
136+ printf ("CreateBitmap failed %lu\n" , cBitsPerPixel );
137+ return FALSE;
138+ }
135139 }
136140
137141 /* Setup bitmap info */
@@ -184,14 +188,17 @@ InitPerBitDepth(
184188 return FALSE;
185189 }
186190
187- SelectObject (* phdcDIB , * phbmpDIB );
191+ if (SelectObject (* phdcDIB , * phbmpDIB ) == NULL )
192+ {
193+ printf ("SelectObject failed for %lu bpp DIB\n" , cBitsPerPixel );
194+ return FALSE;
195+ }
188196
189197 return TRUE;
190198}
191199
192200BOOL GdiToolsInit (void )
193201{
194-
195202 /* Initialize a logical palette */
196203 ghpal = CreatePalette ((LOGPALETTE * )& gpal );
197204 if (!ghpal )
@@ -201,8 +208,8 @@ BOOL GdiToolsInit(void)
201208 }
202209
203210 if (!InitPerBitDepth (1 , 9 , 9 , & ghbmp1 , & ghdcDIB1 , & ghbmpDIB1 , & gpvDIB1 , 0 ) ||
204- !InitPerBitDepth (1 , 9 , 9 , & ghbmp1_InvCol , & ghdcDIB1_InvCol , & ghbmpDIB1_InvCol , & gpvDIB1_InvCol , FL_INVERT_COLORS ) ||
205- !InitPerBitDepth (1 , 9 , 9 , & ghbmp1_RB , & ghdcDIB1_RB , & ghbmpDIB1_RB , & gpvDIB1_RB , FL_RED_BLUE ) ||
211+ !InitPerBitDepth (1 , 9 , 9 , NULL , & ghdcDIB1_InvCol , & ghbmpDIB1_InvCol , & gpvDIB1_InvCol , FL_INVERT_COLORS ) ||
212+ !InitPerBitDepth (1 , 9 , 9 , NULL , & ghdcDIB1_RB , & ghbmpDIB1_RB , & gpvDIB1_RB , FL_RED_BLUE ) ||
206213 !InitPerBitDepth (4 , 5 , 5 , & ghbmp4 , & ghdcDIB4 , & ghbmpDIB4 , & gpvDIB4 , 0 ) ||
207214 !InitPerBitDepth (8 , 5 , 5 , & ghbmp8 , & ghdcDIB8 , & ghbmpDIB8 , & gpvDIB8 , 0 ) ||
208215 !InitPerBitDepth (16 , 8 , 8 , & ghbmp16 , & ghdcDIB16 , & ghbmpDIB16 , & gpvDIB16 , 0 ) ||
0 commit comments