Code sample to access a resource
Posted: Thu Sep 04, 2003 7:40 am
Code updated for 5.20+
I thought it could be useful to alls. Here it is a way to access a RAW Data resource. I use it to store compressed data (it's better than IncludeBinary as a resource is loaded into memory just when needed). As you can see, I pass the buffer to UnPackMemory and it works well.
To compile (by Microsoft's RC) the RES file, I use this source:
Test.txt is actually a binary file converted using bin2txt.exe command. Here it is the MAKE I use (it's a .BAT file).
test.pack is a compressed binary file. The final yourprogram.res file must be added to yourprogram.exe using a program like ResHacker. As I said this way should be better than IncludeBinary, as the data isn't stored in the DATA section of your program and it isn't loaded soon into memory.
I thought it could be useful to alls. Here it is a way to access a RAW Data resource. I use it to store compressed data (it's better than IncludeBinary as a resource is loaded into memory just when needed). As you can see, I pass the buffer to UnPackMemory and it works well.
Code: Select all
nris.l=1 ;-> number of resource
hr=FindResource_(#Null,nris.l,#RT_RCDATA)
If hr
hg=LoadResource_(#Null, hr)
If hg
lpData=LockResource_(hg)
If lpData
*Buffer = AllocateMemory(8000) ;-> your needed size
;decomlu=UncompressMemory(lpData,*Buffer)
;...
;...
EndIf
EndIf
EndIf
Code: Select all
1 RCDATA
BEGIN
#include "test.txt"
END
Code: Select all
@echo off
bin2txt test.pack test.txt
rc yourprogram.rc
pause