Repository navigation
SysWin Resources
Home › All Categories › sys/win › Resources
Reads raw data embedded in a program's resources into a string or out to a file.
A resource script (.rc) compiled into the program can carry whole files: a PNG, a font, a
database, as RCDATA. These two functions find such a resource by name or number and copy its
bytes. The resource itself stays in the module, read-only; nothing has to be freed.
A resource is named either by a text name ("LOGO") or by a number written as text with a
leading # ("#101"). The type defaults to RT_RCDATA (10); pass another type, such as
RT_HTML or a custom type name, as the last argument.
#import "sys/win"
using winA program that copies the resource LOGO out of itself into logo.png. Put the line
LOGO RCDATA "logo.png" in logo.rc and build with tiko logo.tiko logo.rc; built without
the script, it reports that there is none:
#import "sys/win"
using win
dim bytes as string = ExtractResource( NULL, "LOGO" )
if len( bytes ) = 0 then
print "this program carries no LOGO resource"
elseif ExtractResourceToFile( NULL, "LOGO", "logo.png" ) then
print "wrote logo.png,"; len( bytes ); " bytes"
end if| Function | Does |
|---|---|
| ExtractResource | Returns the bytes of a resource as a string. |
| ExtractResourceToFile | Writes the bytes of a resource to a file. |
function ExtractResource( byval hInstance as HINSTANCE, byref wszResourceName as wstring, byval pResourceType as LPWSTR = MAKEINTRESOURCEW(10) ) as stringFinds a resource and returns a copy of its bytes in a string, which is a byte buffer here, not
text: len() is the size of the resource and strptr() points at the first byte.
| Parameter | Meaning |
|---|---|
hInstance |
The module that holds the resource; NULL for the program itself. |
wszResourceName |
The resource name, or # and its number ("#101"). |
pResourceType |
The resource type; RT_RCDATA by default. |
Returns the bytes, or "" when there is no such resource or it is empty.
Example
dim png as string = ExtractResource( NULL, "#101" )
print "resource 101 is"; len( png ); " bytes"Microsoft Learn: FindResourceW
function ExtractResourceToFile( byval hInstance as HINSTANCE, byref wszResourceName as wstring, byref wszFileName as wstring, byval pResourceType as LPWSTR = MAKEINTRESOURCEW(10) ) as booleanFinds a resource and writes its bytes to a file, replacing a file of that name.
| Parameter | Meaning |
|---|---|
hInstance |
The module that holds the resource; NULL for the program itself. |
wszResourceName |
The resource name, or # and its number ("#101"). |
wszFileName |
The path of the file to write. |
pResourceType |
The resource type; RT_RCDATA by default. |
Returns true when the file was written; false when there is no such resource, it is
empty, or the file cannot be created or written.
Example
if ExtractResourceToFile( NULL, "MANUAL", GetExePathName() & "manual.pdf" ) = false then print "no manual"Microsoft Learn: LoadResource
- Category: sys/win
- Paths and files for building the output path
- Images (GDI+) for loading an image straight from a resource
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing