News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Case of the Missing Resource

Started by Mark Jones, February 02, 2005, 10:41:18 PM

Previous topic - Next topic

Mark Jones

Hello. I was tinkering with adding binary data as raw data resources when something strange happened. At first, the Project1.rc file contained:

#include "Project1.h"
2000 RCDATA DISCARDABLE
BEGIN
    Readme.txt
END


Which looks correct, based on what I've seen in various tutorials like AoA and Icez. But it didn't stay that way for long; after laying out dialogs and coding for a few days the resource file now contains:

#include "Project1.h"
2000 256 Res\\Readme.txt


...and nothing I can do will change it back to the way it was. If I add more binary resources, they all appear this way. I tried adding big files, small files, I tried deleting all the resources, restarting EasyCode, and adding them again, to no avail. An error is shown at compile time also:

============== Project1 - Release ==============
Compiling resources...
Project1.h(349) : error RC2007: %#define syntax
RC : fatal error RC1116 : RC terminating after preprocessor errors
Errors ocurred.


Now if I rename the resource handle to _2000 (or any other string) it will compile happily... but the resource file now contains this:

#include "Project1.h"
_2000 256 Res\\Readme.txt



To find this resource in the code at runtime I am trying this:


    Invoke FindResource, hInstance, 2000, RT_RCDATA  ; get handle of Readme.txt
    Mov hResource, Eax


Of course, EAX always returns zero. Is this because the binary data is not being linked right, or am I doing something wrong? Any ideas are much appreciated. :)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Ramon Sala

#1
Hi Mark,

Easy Code looks for raw data resources in Res folder to check if it is a file. If it is, then it writes the path in .rc file (Res\\...). If it is not a file (or the file is not in Res folder), it takes data "as is", so you are responsible to writie it properly for RC compiler to understand it. Some examples of raw data are (that's what you type in Raw Data Resources window):

10,20,30,40                      Four integer (16-bit) values.
"A","B","C","D"                 Four byte (8-bit) values.
"Readme.txt\0"               Not a file, so do not forget double quotes to specify it is a string (null-terminated).
Icon.ico                            It is a file, so Icon.ico file must be in Res folder (Easy Code will add Res\\).


More examples are:

L"Readme.txt\0"             Unicode null-terminated string (L means Unicode, otherwise it is ANSI)
"\r"                                  A control character (8-bit) correspondig to ASCII 13 (<Carriage Return>).
0x40                                 A Hex integer (16-bit) value corresponding to 64 decimal.


This is the syntax that the resource compiler (RC.EXE) needs. In your example, if you write Readme.txt without double quotes and there is no file with that name in Res folder, the data is written "as is" which means nothing to the compiler and generates an error.


Anyway, I'll have a look and try to improve it as much as I can, even though I'm limited by RC compiler syntax.

Ramon


BTW: Do not forget the final zero (\0) if you want a null-terminated string, both ANSI or Unicode. Also, note that any numerical value (in decimal or hex notation) is always a 16-bit integer (Word value in assembler)
Greetings from Catalonia

Ramon Sala

#2
Mark,

Reading your post again, I have realized that you try to find the resource as RT_RCDATA, which is not correct as an RT_RCDATA type cannot specify a file (see RT_RCDATA in RC.HLP). When specifying a file, as long as RC.EXE has no type for it, you must use a "user-defined" resource. User-defined resources must have a value greater than 255, so Easy Code uses the RT_FILEDATA reserved word (ID=256). Then, you should find the resource file like this:

Invoke FindResource, hInstance, 2000, RT_FILEDATA

or:

Invoke FindResource, hInstance, 2000, 256

as RT_FILEDATA = 256.


In the .rc file, Easy Code should write:

#include "Project1.h"
2000 RT_FILEDATA Res\\Readme.txt

instead of:

#include "Project1.h"
2000 256 Res\\Readme.txt

Even though it is the same, it is clearer with the RT_FILEDATA keyword (I'll fix that). So, the resource you are looking for is RT_FILEDATA type, not RT_RCDATA type, so you must specify RT_FILEDATA in the resource type of FindResource function.

Ramon
Greetings from Catalonia

Mark Jones

 Oh thank you Ramon, that works. :U

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Ramon Sala

You are welcome Mark!

As soon as I can, I will write a tutorial about raw data. Sometimes it may be confusing.

Ramon
Greetings from Catalonia