ReactOS 0.4.15-dev-7942-gd23573b
ExtractIconEx.cpp File Reference
#include "shelltest.h"
#include <stdio.h>
Include dependency graph for ExtractIconEx.cpp:

Go to the source code of this file.

Classes

struct  EXTRACTICONTESTS
 

Functions

BOOL FileExists (LPCSTR FileName)
 
BOOL ResourceToFile (INT i, LPCSTR FileName)
 
 START_TEST (ExtractIconEx)
 

Variables

EXTRACTICONTESTS IconTests []
 

Function Documentation

◆ FileExists()

BOOL FileExists ( LPCSTR  FileName)

Definition at line 18 of file ExtractIconEx.cpp.

19{
20 FILE *fp = NULL;
21 bool exists = FALSE;
22
23 fp = fopen(FileName, "r");
24 if (fp != NULL)
25 {
26 exists = TRUE;
27 fclose(fp);
28 }
29 return exists;
30}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)

Referenced by ResourceToFile().

◆ ResourceToFile()

BOOL ResourceToFile ( INT  i,
LPCSTR  FileName 
)

Definition at line 32 of file ExtractIconEx.cpp.

33{
34 FILE *fout;
35 HGLOBAL hData;
36 HRSRC hRes;
37 LPVOID lpResLock;
38 UINT iSize;
39
41 {
42 skip("'%s' already exists. Exiting now\n", FileName);
43 return FALSE;
44 }
45
47 if (hRes == NULL)
48 {
49 skip("Could not locate resource (%d). Exiting now\n", i);
50 return FALSE;
51 }
52
53 iSize = SizeofResource(NULL, hRes);
54
55 hData = LoadResource(NULL, hRes);
56 if (hData == NULL)
57 {
58 skip("Could not load resource (%d). Exiting now\n", i);
59 return FALSE;
60 }
61
62 // Lock the resource into global memory.
63 lpResLock = LockResource(hData);
64 if (lpResLock == NULL)
65 {
66 skip("Could not lock resource (%d). Exiting now\n", i);
67 return FALSE;
68 }
69
70 fout = fopen(FileName, "wb");
71 fwrite(lpResLock, iSize, 1, fout);
72 fclose(fout);
73 return TRUE;
74}
BOOL FileExists(LPCSTR FileName)
#define skip(...)
Definition: atltest.h:64
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
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_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 RT_RCDATA
Definition: pedump.c:372
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( ExtractIconEx  )

Definition at line 98 of file ExtractIconEx.cpp.

99{
100 UINT i, nReturnedIcons, nExtractedIcons;
101 CHAR FileName[2][13] = { "ROS.ico", "sysicon.ico" };
102
103 if (!ResourceToFile(2, FileName[0]))
104 return;
105 if (!ResourceToFile(3, FileName[1]))
106 return;
107
108 /* Check count of icons returned */
109 for (i = 0; i < _countof(IconTests); ++i)
110 {
111 nReturnedIcons = ExtractIconExW(IconTests[i].pszFilePath, -1, NULL, NULL, 0);
112 ok(nReturnedIcons == IconTests[i].nIcons, "ExtractIconExW(%u): Expects %u icons, got %u\n", i, IconTests[i].nIcons, nReturnedIcons);
113 }
114
115 /* Check if the 0th icon can be extracted successfully */
116 for (i = 0; i < _countof(IconTests); ++i)
117 {
118 nExtractedIcons = ExtractIconExW(IconTests[i].pszFilePath, 0, NULL, NULL, 1);
119 ok(nExtractedIcons == IconTests[i].nIcons, "ExtractIconExW(%u): Expects %u icons, got %u\n", i, IconTests[i].nIcons, nExtractedIcons);
120 }
121
124}
BOOL ResourceToFile(INT i, LPCSTR FileName)
EXTRACTICONTESTS IconTests[]
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:849
#define _countof(array)
Definition: sndvol32.h:68
char CHAR
Definition: xmlstorage.h:175

Variable Documentation

◆ IconTests

EXTRACTICONTESTS IconTests[]
Initial value:
=
{
{L"%SystemRoot%\\System32\\cmd.exe", 1},
{L"%SystemRoot%\\System32\\autochk.exe", 0},
{L"%SystemRoot%\\non-existent-file.sdf", 0},
{L"%SystemRoot%\\explorer.exe", 18},
{L"sysicon.ico", 1},
{L"ROS.ico", 0}
}
#define L(x)
Definition: ntvdm.h:50

Definition at line 76 of file ExtractIconEx.cpp.

Referenced by START_TEST().