-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResType.cpp
More file actions
233 lines (184 loc) · 5.96 KB
/
ResType.cpp
File metadata and controls
233 lines (184 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*******************************************************************
// Copyright (c) 2000, Robert Umbehant
// mailto:rumbehant@wheresjames.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later
// version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
//
*******************************************************************/
// ResType.cpp: implementation of the CResType class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#ifndef IS_INTRESOURCE
#define IS_INTRESOURCE( w ) ( ( ( (DWORD)w ) & 0xffff0000 ) == 0 )
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CResType::CResType()
{_STT();
m_hModule = NULL;
*m_szType = 0;
m_dwType = 0;
m_dwMaxEnum = MAXDWORD;
}
CResType::~CResType()
{_STT();
Destroy();
}
void CResType::Destroy()
{_STT();
FreeMod();
*m_szType = 0;
m_dwType = 0;
m_dwMaxEnum = MAXDWORD;
}
void CResType::FreeMod()
{_STT();
// Unload module if needed
if ( m_bUnload && m_hModule != NULL )
FreeLibrary( m_hModule );
m_bUnload = FALSE;
m_hModule = NULL;
}
BOOL CALLBACK CResType::EnumResNameProc( HMODULE hModule, LPCTSTR lpszType,
LPTSTR lpszName, LPARAM lParam )
{_STT();
CResType* pResType = (CResType*)lParam;
if ( pResType == NULL ) return FALSE;
return pResType->OnEnum( hModule, lpszType, lpszName );
}
BOOL CResType::Enum(LPCTSTR pFile, LPCTSTR pType, DWORD max)
{_STT();
// Lose previous module
Destroy();
// Attempt to load the file
m_hModule = LoadLibraryEx( pFile, NULL, LOAD_LIBRARY_AS_DATAFILE );
if ( m_hModule == NULL ) return FALSE;
// Need to unload this one
m_bUnload = TRUE;
// Save resource type
m_dwType = (LPVOID)pType;
if ( !IS_INTRESOURCE( pType ) ) strcpy_sz( m_szType, pType );
// How many do they want?
m_dwMaxEnum = max;
// Enum the resources
return EnumResourceNames( m_hModule, pType, CResType::EnumResNameProc, (LONG)RUPTR2INT(this) );
}
BOOL CResType::Enum(HMODULE hMod, LPCTSTR pType, DWORD max)
{_STT();
// Lose previous module
Destroy();
// Save module handle
m_hModule = ( hMod != NULL ) ? hMod : GetModuleHandle( NULL );
// Save resource type
m_dwType = (LPVOID)pType;
if ( !IS_INTRESOURCE( pType ) ) strcpy_sz( m_szType, pType );
// How many do they want?
m_dwMaxEnum = max;
// Enum the resources
return EnumResourceNames( hMod, pType, CResType::EnumResNameProc, (LONG)RUPTR2INT(this) );
}
BOOL CResType::OnEnum(HMODULE hModule, LPCTSTR pType, LPCTSTR pName)
{_STT();
// Do we want to enum any more?
if ( Size() >= m_dwMaxEnum ) return FALSE;
// Add it
return Add( pName );
}
BOOL CResType::Add(LPCTSTR pName)
{_STT();
LPVOID dwName = (LPVOID)pName;
LPCTSTR szName = pName;
// What kind of title is it?
if ( IS_INTRESOURCE( dwName ) ) szName = NULL;
// Allocate node
LPRESTYPEINFO prti = (LPRESTYPEINFO)New( NULL, dwName, szName );
if ( prti == NULL ) return FALSE;
return TRUE;
}
BOOL CResType::LoadResource(LPCTSTR pResource, LPBYTE pPtr, LPDWORD pdwSize, LPCTSTR pType, HMODULE hModule)
{_STT();
if ( pResource == NULL ) return FALSE;
// Find the resource
HRSRC hRsrc = FindResource( hModule, pResource, pType );
if ( hRsrc == NULL ) return FALSE;
// Save the size
DWORD dwSize = SizeofResource( hModule, hRsrc );
if ( pdwSize != NULL ) *pdwSize = dwSize;
// Is this all they wanted to know
if ( pPtr == NULL ) return TRUE;
// Don't copy if size is zero
if ( dwSize == 0 ) return TRUE;
// Load the resource
HGLOBAL hGlobal = ::LoadResource( hModule, hRsrc );
if ( hGlobal == NULL ) return FALSE;
// Lock the resource
LPBYTE pData = (LPBYTE)LockResource( hGlobal );
if ( pData == NULL )
{
FreeResource( hGlobal );
return FALSE;
} // end if
// Copy the data
memcpy( pPtr, pData, dwSize );
// Done with this resource
FreeResource( hGlobal );
return TRUE;
}
LPCTSTR CResType::GetType( LPVOID dwType, LPCTSTR pType )
{_STT();
// What type of identifier is it?
if ( IS_INTRESOURCE( dwType ) )
return (LPCTSTR)dwType;
return pType;
}
HICON CResType::LoadIcon(LPRESTYPEINFO prti, DWORD i, LPDWORD count)
{_STT();
// Verify pointer
if ( prti == NULL ) return NULL;
/*
// Check for group icon
if ( GetType() == RT_GROUP_ICON )
{
// Find the resource
DWORD size = 0;
if ( !LoadResource( GetType( prti->user, prti->cpkey ), NULL, &size, GetType(), m_hModule )
|| size == 0 ) return NULL;
TMem< BYTE > mem;
if ( !mem.allocate( size ) ) return FALSE;
// Get a pointer
LPGRPICONDIR pgid = (LPGRPICONDIR)mem.ptr();
if ( pgid == NULL ) return FALSE;
// Let user know the score
if ( count != NULL ) *count = pgid->idCount;
// Is the index reasonable?
if ( i > pgid->idCount ) return FALSE;
// Return the icon
return ::LoadIcon( m_hModule, MAKEINTRESOURCE( pgid->idEntries[ i ].nID ) );
} // end if
*/
// Attempt to load the icon
return ::LoadIcon( m_hModule, GetType( prti->user, prti->cpkey ) );
}
LPRESTYPEINFO CResType::FindRes(LPCTSTR pRes)
{_STT();
// Check for int
if ( IS_INTRESOURCE( pRes ) ) return (LPRESTYPEINFO)CLList::Find( (LPVOID)pRes );
// Find string
return (LPRESTYPEINFO)Find( pRes );
}