ReactOS 0.4.15-dev-8219-ge8b88cf
LoadImageGCC.c File Reference
#include "precomp.h"
#include "resource.h"
#include <stdio.h>
#include <versionhelpers.h>
Include dependency graph for LoadImageGCC.c:

Go to the source code of this file.

Functions

BOOL FileExistsW (PCWSTR FileName)
 
BOOL ResourceToFileW (INT i, PCWSTR FileName)
 
 START_TEST (LoadImageGCC)
 

Variables

struct {
   PCWSTR   FileName
 
   INT   ResourceId
 
DataFiles []
 

Function Documentation

◆ FileExistsW()

BOOL FileExistsW ( PCWSTR  FileName)

Definition at line 16 of file LoadImageGCC.c.

17{
19
20 return (Attribute != INVALID_FILE_ATTRIBUTES &&
21 !(Attribute & FILE_ATTRIBUTE_DIRECTORY));
22}
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23

Referenced by ResourceToFileW().

◆ ResourceToFileW()

BOOL ResourceToFileW ( INT  i,
PCWSTR  FileName 
)

Definition at line 24 of file LoadImageGCC.c.

25{
26 FILE *fout;
27 HGLOBAL hData;
28 HRSRC hRes;
29 PVOID pResLock;
30 UINT iSize;
31
33 {
34 /* We should only be using %temp% paths, so deleting here should be OK */
35 printf("Deleting '%S' that already exists.\n", FileName);
37 }
38
40 if (hRes == NULL)
41 {
42 skip("Could not locate resource (%d). Exiting now\n", i);
43 return FALSE;
44 }
45
46 iSize = SizeofResource(NULL, hRes);
47
48 hData = LoadResource(NULL, hRes);
49 if (hData == NULL)
50 {
51 skip("Could not load resource (%d). Exiting now\n", i);
52 return FALSE;
53 }
54
55 // Lock the resource into global memory.
56 pResLock = LockResource(hData);
57 if (pResLock == NULL)
58 {
59 skip("Could not lock resource (%d). Exiting now\n", i);
60 return FALSE;
61 }
62
63 fout = _wfopen(FileName, L"wb");
64 fwrite(pResLock, iSize, 1, fout);
65 fclose(fout);
66 return TRUE;
67}
BOOL FileExistsW(PCWSTR FileName)
Definition: LoadImageGCC.c:16
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
#define printf
Definition: freeldr.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define RT_RCDATA
Definition: pedump.c:372
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( LoadImageGCC  )

Definition at line 79 of file LoadImageGCC.c.

80{
81 UINT i;
82 WCHAR PathBuffer[MAX_PATH];
83 static HBITMAP hBmp;
85 HDC hdcMem;
87 BITMAPINFO bmi;
88 HGLOBAL hMem;
89 LPVOID lpBits;
90 CHAR img[8] = { 0 };
91 UINT size;
92
93 /* Windows 2003 cannot run this test. Testman shows CRASH, so skip it. */
94 if (!IsReactOS())
95 return;
96
97 /* Extract Data Files */
98 for (i = 0; i < _countof(DataFiles); ++i)
99 {
100 ExpandEnvironmentStringsW(DataFiles[i].FileName, PathBuffer, _countof(PathBuffer));
101
102 if (!ResourceToFileW(DataFiles[i].ResourceId, PathBuffer))
103 {
104 printf("ResourceToFile Failed. Exiting now\n");
105 goto Cleanup;
106 }
107 }
108
111
113 SelectObject(hdcMem, hBmp);
114 GetObject(hBmp, sizeof(BITMAP), &bitmap);
115
116 memset(&bmi, 0, sizeof(bmi));
117 memset(&bmi, 0, sizeof(bmi));
118 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
119 bmi.bmiHeader.biWidth = bitmap.bmWidth;
120 bmi.bmiHeader.biHeight = bitmap.bmHeight;
121 bmi.bmiHeader.biPlanes = bitmap.bmPlanes;
122 bmi.bmiHeader.biBitCount = bitmap.bmBitsPixel;
124 bmi.bmiHeader.biSizeImage = 0;
125
126 size = ((bitmap.bmWidth * bmi.bmiHeader.biBitCount + 31) / 32) * 4 * bitmap.bmHeight;
127
129 lpBits = GlobalLock(hMem);
130 GetDIBits(hdcMem, hBmp, 0, bitmap.bmHeight, lpBits, &bmi, DIB_RGB_COLORS);
131
132 /* Get first 8 bytes of second row of bits from bitmap */
133 memcpy(img, (VOID *)((INT_PTR)lpBits + 4 * bitmap.bmWidth), 8);
134
135 ok(img[0] == 0, "Byte 0 Bad. Got 0x%02x, expected 0\n", img[0] & 0xff);
136 ok(img[1] == 0, "Byte 1 Bad. Got 0x%02x, expected 0\n", img[1] & 0xff);
137 ok(img[2] == 0, "Byte 2 Bad. Got 0x%02x, expected 0\n", img[2] & 0xff);
138 ok(img[3] == 0, "Byte 3 Bad. Got 0x%02x, expected 0\n", img[3] & 0xff);
139
140 GlobalUnlock(hMem);
141 GlobalFree(hMem);
142
144
145Cleanup:
146 for (i = 0; i < _countof(DataFiles); ++i)
147 {
148 ExpandEnvironmentStringsW(DataFiles[i].FileName, PathBuffer, _countof(PathBuffer));
149 DeleteFileW(PathBuffer);
150 }
151}
INT ResourceId
Definition: LoadImageGCC.c:72
BOOL ResourceToFileW(INT i, PCWSTR FileName)
Definition: LoadImageGCC.c:24
static struct @1610 DataFiles[]
#define ok(value,...)
Definition: atltest.h:57
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
static const WCHAR Cleanup[]
Definition: register.c:80
#define BI_RGB
Definition: precomp.h:56
GLint GLvoid * img
Definition: gl.h:1956
GLsizeiptr size
Definition: glext.h:5919
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
#define memset(x, y, z)
Definition: compat.h:39
#define _countof(array)
Definition: sndvol32.h:70
Definition: bl.h:1331
Definition: uimain.c:89
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
int32_t INT_PTR
Definition: typedefs.h:64
HDC hdcMem
Definition: welcome.c:104
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
#define GMEM_MOVEABLE
Definition: winbase.h:294
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define GetObject
Definition: wingdi.h:4468
BOOL WINAPI DeleteDC(_In_ HDC)
#define IMAGE_BITMAP
Definition: winuser.h:211
#define LoadImage
Definition: winuser.h:5824
#define LR_DEFAULTCOLOR
Definition: winuser.h:1087
#define MAKEINTRESOURCE
Definition: winuser.h:591
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Variable Documentation

◆ 

struct { ... } DataFiles[]
Initial value:
=
{
{L"%SystemRoot%\\bin\\image.dll", IDR_DLL_NORMAL},
}
#define IDR_DLL_NORMAL
Definition: resource.h:7

Referenced by START_TEST().

◆ FileName

Definition at line 71 of file LoadImageGCC.c.

◆ ResourceId