TIEResourceExtractor.GetBuffer
Declaration
function GetBuffer(TypeIndex: integer; NameIndex: integer; var BufferLength: integer): pointer; overload;
function GetBuffer(const TypeStr: AnsiString; const NameStr: AnsiString; var BufferLength: integer): pointer; overload;
function GetBuffer(const ResourceType: TIEResourceType; const NameStr: AnsiString; var BufferLength: integer): pointer; overload;
function GetBuffer(ResourceBookmark: TIEResourceBookmark; var BufferLength: integer): pointer; overload;
function GetBuffer(ResourceType: TIEResourceBookmark; const Index: Integer; var BufferLength: integer): pointer; overload;
Description
Returns memory buffer for the specified resource.
Parameter | Description |
TypeIndex | Index of resource type. 0 is first resource type, TypesCount-1 is the last resource type |
NameIndex | Index of actual resource. 0 is first resource name, NamesCount-1 is the last resource name |
BufferLength | Field filled with the resulting buffer length (in bytes) |
TypeStr | Type as string, e.g. 'Bitmap', 'Cursor' or 'RCData' or ResourceType, e.g. ietrBitmap |
NameStr | Resource name as string, e.g. 'INTRESOURCE:100' or 'Hand' |
ResourceBookmark | A resource bookmark returned by GetResourceBookmark |
The buffer must not be freed.
// Extract the first icon in Windows Explorer
re := TIEResourceExtractor.Create('C:\Windows\Explorer.exe');
try
buffer := re.GetBuffer( 'Icon', 'INTRESOURCE:1', bufferLen );
ImageEnView1.IO.Params.IsResource := True;
if ImageEnView1.IO.LoadFromBuffer( buffer, bufferLen ) then
ImageEnView1.IO.SaveToFile( 'D:\Explorer.ico' );
finally
re.Free;
end;
// Load resource 143 of type "Bitmap" from current application
var
re: TIEResourceExtractor;
buffer: pointer;
bufferLen: integer;
begin
re := TIEResourceExtractor.Create( Application.ExeName );
try
buffer := re.GetBuffer('Bitmap', 'INTRESOURCE:143', bufferLen);
ImageEnView1.IO.Params.IsResource := True;
ImageEnView1.IO.LoadFromBuffer(buffer, bufferLen, ioBMP);
finally
re.Free;
end;
end;
// Load the 5th resource of type "RCData" from current application
var
re: TIEResourceExtractor;
buffer: pointer;
bufferLen: integer;
begin
re := TIEResourceExtractor.Create( Application.ExeName );
try
buffer := re.GetBuffer( ietrRCData, 5, bufferLen);
ImageEnView1.IO.Params.IsResource := True;
ImageEnView1.IO.LoadFromBuffer( buffer, bufferLen, ioUnknown );
finally
re.Free;
end;
end;
// Load the resource specified by "TypeIndex" and "NameIndex"
var
buffer: pointer;
bufferLen: integer;
begin
buffer := m_ResourceExtractor.GetBuffer(resTypeIndex, resNameIndex, bufferLen);
ImageEnView1.IO.Params.IsResource := true;
if m_ResourceExtractor.ResourceTypes[resTypeIndex] = ietrBitmap then
ImageEnView1.IO.LoadFromBuffer(buffer, bufferLen, ioBMP)
else
if m_ResourceExtractor.ResourceTypes[resTypeIndex] = ietrCursor then
ImageEnView1.IO.LoadFromBuffer(buffer, bufferLen, ioCUR)
else
if m_ResourceExtractor.ResourceTypes[resTypeIndex] = ietrIcon then
ImageEnView1.IO.LoadFromBuffer(buffer, bufferLen, ioICO)
else
// We cannot use ioUnknown (autodect) for BMP, CUR and ICO because it is not possible to autodetect BMP, CUR and ICO when they are resources.
ImageEnView1.IO.LoadFromBuffer(buffer, bufferLen, ioUnknown) // for jpegs, GIF, etc...
end;