View Full Version : Resources [Non-VCL]
I've been wondering about this for a while now, is there a way to read resources (*.res) without using the VCL classes? I cleaned up my demosystem today, and I found out that it would save me 20-25kb to do the resource stuff without the VCL, and since I'm doing 64kb's, thats a lot.. An alternative way of including MIDI files in a tight way would also be much appriciated..
25-06-2004, 06:16 PM
Look up "Resource Functions" in windows sdk help
..and there it was. Thanks as usual Paulius ;)
I have to sart using the Win SDK help files more.. I kinda forget they excist :oops:
The SDK is driving me insane! I did a proc to find and save a resource to file. The code looks like this:
//Finds and saves a resource to specified file.
function SaveResource(Filename,ResID,ResType: PChar):boolean;
if SoundRes=0 then
MessageBox(0,PChar('Error loading '+ResID+' resource'+#13+'Error code '+inttostr(GetLastError)),'Error!',0);
FileHandle:=CreateFile(Filename, GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,0);
if WriteFile(FileHandle,SoundRes,SoundResSize,NumByte sWritten,0)=false then
MessageBox(0,PChar('Failed to write data to '+Filename+#13+'Error code '+inttostr(GetLastError)),'Error!',0);
The resource is found, the size of the resource is the correct one, SoundRes is really pointing to the memory block it's supposed to, yet, it won't write content to the output file. I figured the error must be in WriteFile(FileHandle,SoundRes,SoundResSize,NumByte sWritten,0) so I have tried every possible changes to it without luck. I have tried using Locked and SoundResHandle instead of SoundRes and I have tried using the OVERLAPPED structure. But I can't get it right. I get the custom buffer error when doing WriteFile();
I have read the SDK documentation so many times now, that I had nightmares about the evil structures comming to get me.. Any help greatly appriciated..
27-06-2004, 04:39 PM
WriteFile wants a pointer not a handle so you should be passing "Locked" instead of "SoundRes", do you get the same error using it?
Yeah, get the same error...
I noticed something earlier though, I thought I'd experiment with WriteFile so I wrote a constant number at the BytesToWrite. When the number was <3000 bytes, the file was filled with data, but when it was over, it pushed an error. This isn't excactly logical, since the pointer pointed to a place in memory containing 26322 bytes.
27-06-2004, 06:01 PM
Damn lying documentation, it doesn't want a pointer, so it actually should be Locked^
You're brilliant! :D it works like a charm now! Boy I would have been struggling with this for weeks. ;) Thanks a lot! :)
btw; to compare the changes from using TResourceStreem to this:
With TResourceStreem my exe containing a 24kb MIDI was 74kb compressed with UPX. When using this, the exe is 65 UNCOMPRESSED and 21kb (!!) compressed with a 24kb MIDI. This file also containes the playback engine for my demosystem, AND a datafile for the intro :)
Powered by vBulletin® Version 4.1.10 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.