📄 res32.htm
字号:
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>win32 resource file format</title>
</head>
<basefont size="3">
<body bgcolor="#ffffff" text="#000000" topmargin="0"
background="../jpg/di1.JPG">
<hr align="left">
<font size="+2">
<p>win32 resource file format</font> </p>
<hr align="left">
<font size="-1">
<p>by <a href="mailto:d3k@mdnet.it">marco cocco</a>, of <a
href="http://www.mdlive.com/d3k/">d3k - the artisan of ware</a>, italy</font> </p>
<p><b><font size="+1">introduction</font></b> </p>
<p><b>preface</b><br>
welcome to the win32 resource file format reference guide !<br>
this document is a guide to reading/writing windows 95 and windows nt resource files (res
extension).<br>
this guide has been written by <a href="mailto:d3k@mdnet.it">m.cocco</a> (of <a
href="http://www.mdlive.com/d3k/">d3k - the artisan of ware</a>, italy) while developing
the makeres resource editor, a tool of the "photoshop plug-in toolkit" for
delphi 2.0. <br>
<br>
<font size="-2">copyright (c) 1997, marco cocco. all rights reserved.<br>
copyright (c) 1997, d3k - the artisan of ware. all rights reserved.<br>
</font></p>
<p><b>audience</b><br>
this guide is for any programmers who have written applications for windows systems and
wish to understand how to work with standalone binary resource file (res files, not in-exe
resources). this guide assumes you are proficient in the windows programming and have
worked in any development environments such as borland delphi 2.0, borland delphi 3.0,
borland c++ builder, microsoft visual c++ (on windows 95 or windows nt).<br>
you should have a working knowledge of the different resource types, and understand how
handle binary files. this guide assumes you understand terminology such as records
(structures), word and dword types, strings (ansi and unicode), record (structure)
alignment, etc. </p>
<p><b>remarks</b><br>
this documentation is made to provide specific information on implementation and
structuring issues for win32 resource files only. win16 resource files are not explained
in this guide.<br>
the best way to use this guide is to read it all without skipping any chapter.<br>
<br>
should you have any question, feel free to contact the author. </p>
<p><b><font size="+1">getting started</font></b> </p>
<p>this document details the structure of the resource binary file (.res) format for win32
platforms (w95 and wnt). the structure is very similar to the existing win16
(w3/w3.1/3.11) structure, but it supports some new data types and data structures.<br>
one important enhancement is the dword/word alignment of structures/fields which increases
performance of new 32 bit microprocessors but makes resource reading/writing a bit more
complex (structures are of dynamic size). the order of the fields of resource data
structures is not changed due to alignment, but some padding is required between fields.<br>
<br>
the win32 resource file contains one or more binary resources merged in a single file and
aligned on dword boundaries. each resource has its own header structure followed by
resource data. immediately after the resource data comes the header for the next resource
followed by resource data, and so on.<br>
<br>
to read/write resource files you must have knowledge of binary files handling. resource
files cannot be read using text mode file routines.<br>
<br>
</p>
<p><b><font size="+1">the resource header</font></b> </p>
<p>the structure of the header is as follows:<br>
<br>
</p>
<table border="1" bgcolor="white" cellpadding="2" cellspacing="0" width="100%">
<tr bgcolor="black">
<td><font color="white"><b>offset</b></font> </td>
<td><font color="white"><b>field</b></font> </td>
<td><font color="white"><b>data type</b></font> </td>
<td><font color="white"><b>description</b></font> </td>
</tr>
<tr>
<td align="center">0 </td>
<td>datasize </td>
<td>dword<br>
<font size="-1">4 bytes, 32 bit unsigned integer</font> </td>
<td>the size of the data that follows the header (not including any padding). </td>
</tr>
<tr>
<td align="center">4 </td>
<td>headersize </td>
<td>dword<br>
<font size="-1">4 bytes, 32 bit unsigned integer</font> </td>
<td>the size of the header structure. </td>
</tr>
<tr>
<td align="center">8 </td>
<td>restype </td>
<td>ordinal or unicode string<br>
<font size="-1">array of 16 bit unsigned integers (2 bytes each)</font> </td>
<td>resource type id (standard or custom). </td>
</tr>
<tr>
<td align="center">ofsof(restype)+sizeof(restype)+padding </td>
<td>resname </td>
<td>ordinal or unicode string<br>
<font size="-1">array of 16 bit unsigned integers (2 bytes each)</font> </td>
<td>resource name. </td>
</tr>
<tr>
<td align="center">ofsof(resname)+sizeof(resname)+padding </td>
<td>dataversion </td>
<td>dword<br>
<font size="-1">4 bytes, 32 bit unsigned integer</font> </td>
<td>determines the format of the information within the resource header that follows. not
currently used. should be zeroed. </td>
</tr>
<tr>
<td align="center">ofsof(dataversion)+4 </td>
<td>memoryflags </td>
<td>word<br>
<font size="-1">2 bytes, 16 bit unsigned integer</font> </td>
<td>the state of the resource. </td>
</tr>
<tr>
<td align="center">ofsof(memoryflags)+2 </td>
<td>languageid </td>
<td>word<br>
<font size="-1">2 bytes, 16 bit unsigned integer</font> </td>
<td>the language that the strings are written with. </td>
</tr>
<tr>
<td align="center">ofsof(languageid)+2 </td>
<td>version </td>
<td>dword<br>
<font size="-2">4 bytes, 32 bit unsigned integer</font> </td>
<td>it has no significance to the system. used by resource editors. usually zeroed. </td>
</tr>
<tr>
<td align="center">ofsof(version)+4 </td>
<td>characteristics </td>
<td>dword<br>
<font size="-2">4 bytes, 32 bit unsigned integer</font> </td>
<td>it has no significance to the system. used by resource editors. usually zeroed. </td>
</tr>
</table>
<p><br>
- resource header structure is not of fixed length. <b>you have to read/write header
fields one at a time.</b><br>
- resource headers ever start on a dword boundary.<br>
- when reading a res file you must move the file pointer to next nearest dword boundary
(only if current file pointer is not already on a dword boundary).<br>
- when writing a res file you must write as much padding bytes as it is required to let
the header be dword aligned (only if current file pointer is not already on a dword
boundary).<br>
<br>
more about the resource header fields:<br>
<br>
</p>
<table border="1" bgcolor="white" cellpadding="2" cellspacing="0" width="100%">
<tr bgcolor="black">
<td><font color="white"><b>field</b></font> </td>
<td><font color="white"><b>additional information</b></font> </td>
</tr>
<tr>
<td>datasize </td>
<td>the size of the data that follows the header. this value does not include any file
padding bytes added after the actual data.<br>
the format of the data is different for any of the possible resource types. data size is
expressed in bytes (8 bit unsigned integer). </td>
</tr>
<tr>
<td>headersize </td>
<td>the size of the resource header structure. this value <b>includes </b>the size of the
datasize and headersize fields.<br>
the value of headersize is expressed in bytes and can be used to seek directly to resource
data following the resource header (seek to filepos(datasize) + headersize).<br>
<font size="-1">the win32 sdk wrongly says: "the headersize field gives the size of
the resource header structure <i>that follows</i>". this should be read: "the
headersize field gives the size of the resource header structure, <i>including the
datasize field and the headersize field itself</i>". </font></td>
</tr>
<tr>
<td>restype </td>
<td>specifies the resource type (its integer code or its alphabetic name).<br>
<font size="-1"><b>further explanation of this field can be found in "the restype
field" chapter.</b></font> </td>
</tr>
<tr>
<td>resname </td>
<td>specifies the name of resource (its integer name-code or its alphabetic name).<br>
<font size="-1"><b>further explanation of this field can be found in "the resname
field" chapter.</b></font> </td>
</tr>
<tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -