The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: mike2 on August 07, 2011, 03:24:34 PM

Title: Resource compiler problem
Post by: mike2 on August 07, 2011, 03:24:34 PM
I have a problem with MASM and the resource compiler. Normally, a *.RC script looks like this
#define IDD_DIALOG1 100
[...]
IDD_DIALOG1 DIALOG 0, 0, 100, 200
[...]


The "#define" part is often written inside a "resource.h", which is included by the resource compiler. If I include the "resource.h" in my ASM file, I will of course get an error since #define is not ASM but C code. I solved this problem with a simpe macro
#define MACRO a, b
a equ <b>
ENDM


This macro always allowed me to just include the header file without having to copy&paste&edit the "#define IDD_DIALOG1 100" to "IDD_DIALOG1 equ 100" every time I change something. This works fine with TASM, but MASM will fail and tell me that the unknown charater "#" is on a line.

How do I solve this problem? MASM doesn't accept "#define" syntax und RC doesn't support "equ" syntax. Having two different include files with different syntax notation is hard to maintain and a big error source.
Title: Re: Resource compiler problem
Post by: dedndave on August 07, 2011, 03:33:01 PM
at the top of the resource file.....

#include  "\masm32\include\resource.h"

it's best if it's the first thing in the file

for more info, refer to
\masm32\bin\rc.hlp

msdn also has docs...
http://msdn.microsoft.com/en-us/library/aa381042%28v=vs.85%29.aspx

some time ago, Hutch posted an updated resource.h file
i see that Yves posted one also, saying it is more complete
his zip file is smaller - you'd have to check them out to see which is best   :P

http://www.masm32.com/board/index.php?topic=12791.msg98764#msg98764

i am not sure how you'd get masm to like # as the first char on a line
but there are tools around that will convert header files to include files
h2inc - Vortex and/or Donkey's site
Title: Re: Resource compiler problem
Post by: dedndave on August 07, 2011, 03:59:27 PM
here we go - found it on Andreas' site...
http://www.japheth.de/

not sure how well that will work out
Hutch may have translated many of the defines in resource.h to equates in windows.inc
Title: Re: Resource compiler problem
Post by: ToutEnMasm on August 07, 2011, 04:07:24 PM
Quote
How do I solve this problem? MASM doesn't accept "#define" syntax und RC doesn't support

I think a simple trick can solve this.With the editor ,change  # with A or other chain and masm wil be happy.
Rename your macro also.
Title: Re: Resource compiler problem
Post by: mike2 on August 07, 2011, 04:17:03 PM
You missunderstood me. I don't need any official "resource.h" translated to INC syntax, I'm talking about project specific ones.

test.rc

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"

//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG1 DIALOG 0, 0, 400, 400
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Test Application"
FONT 8, "Ms Shell Dlg"
{
    EDITTEXT        IDD_EDIT1, 15, 30, 50, 12, ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER
    EDITTEXT        IDD_EDIT2, 100, 30, 30, 12, ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER
}


resource.h

#define IDD_DIALOG1      100
#define IDD_EDIT1        1000
#define IDD_EDIT2        1001


I need all the IDD_* constants in my ASM code, so I somehow have to include them. I could write something like

IDD_DIALOG1 equ 100
IDD_EDIT1 equ 1000
IDD_EDIT2 equ 1001

in my ASM code, but the constants can (and will) change nearly every time I add or remove items from the resource script. I can't edit the "resource.h" since it is autogenerated every time I save the resource script.

@ToutEnMasm:
I know that "Adefine" would be a valid MASM macro, but it's nothing which the resource compiler understands. The resource compiler must have "#define", I'm looking for a way to make MASM acccept it.
Title: Re: Resource compiler problem
Post by: ToutEnMasm on August 07, 2011, 04:37:58 PM

Quote
I'm looking for a way to make MASM acccept it
There is no way to do that. #define is a reserved word even for masm.

the best you can do is this:

Adefine MACRO a,b
   a equ <b>
ENDM   
Adefine MACHIN , 3251
Title: Re: Resource compiler problem
Post by: mike2 on August 07, 2011, 05:01:36 PM
#define is no reserverd word in MASM. It will fail also on a macro named "#dzisogziosdfiosgzadgsdsgd" telling me that "#" is an invalid char.

As I already said, I can't edit "resource.h" since it is an autogenerated file which gets overwritten every time I save the project.

Writing "Adefine MACHIN , 3251" would be useless since I could as well write "MACHIN equ 3251" without using a macro. But that has the disadvantages I already explained above.
Title: Re: Resource compiler problem
Post by: ToutEnMasm on August 07, 2011, 05:06:04 PM

The result is the same.You couldn't begin any word by #.
Title: Re: Resource compiler problem
Post by: dedndave on August 07, 2011, 05:19:47 PM
it is not reserved, but it breaks MASM rules for naming labels
all labels have to start with a letter, underscore, dollar-sign, and maybe a few other characters

it is not a MASM problem, per se   :P

unfortunately, the resource compiler has no macro support
if it did, you could write a macro to convert EQUate's to #define's

what you want to do is find a way to train the IDE   :bg

the only other thing i can think of, offhand.....

1) write a MASM macro that ECHO's the EQUate to the display
2) for EQUate's that you want in the RC file, use the macro instead of EQU
3) redirect the MASM text output to a file
4) in the assembly batch file, a little program comes in there and finds the ECHO's in the text file and adds them to the RC file   :U
5) pay me $50 for the idea
Title: Re: Resource compiler problem
Post by: Tedd on August 07, 2011, 06:30:20 PM
Alternatively...

1) Create a text file - mydefs.txt - containing the required names and values (one per line, separated by a space)
2) Write a little program which reads in this text file, and writes its output to two files - mydefs.inc and mydefs.h - in the relevant formats
3) Modify your asm source to include mydefs.inc, and your rc script to include mydefs.h
4) Each time you need to modify the values: update mydefs.txt and run the tool to generate the new inc & h files
5) Save your money and time
Title: Re: Resource compiler problem
Post by: dedndave on August 07, 2011, 09:04:10 PM
here we go.....

1) place the #DEFINE's that you want to appear in the ASM source into a seperate H file
2) in the resource file (or perhaps, in the resource.h file) use #INCLUDE to add that file to the resource
3) in the batch file, use Erol's def2inc or Andreas' inc2hX to create an INC file

Erol's def2inc
http://www.vortex.masmcode.com/

Andreas' inc2hX
http://www.japheth.de/

4) in the ASM file, include the INC file in the desired location using INCLUDE
5) pay me $100, as you did not have to write a program   :dance:
Title: Re: Resource compiler problem
Post by: mike2 on August 08, 2011, 07:41:23 AM
Quote from: dedndave on August 07, 2011, 09:04:10 PM2) in the resource file (or perhaps, in the resource.h file) use #INCLUDE to add that file to the resource
Like I already said twice, I can't edit the resource file, since it will be overwritten every time I save the project.

I now included h2ash in my makefile and *.ash in my ASM source, It does probably the same as def2inc or h2inc would do. It comes with TASM, I already paid for it 15 years ago. :bg
Title: Re: Resource compiler problem
Post by: hutch-- on August 08, 2011, 08:08:10 AM
Mike, I keep the world simple with resource scripts, I use numbers directly with no equates.
Title: Re: Resource compiler problem
Post by: dedndave on August 08, 2011, 10:20:40 AM
QuoteLike I already said twice, I can't edit the resource file, since it will be overwritten every time I save the project.

the work-around for that is to add an #include statement in the resurce.h file to add your small def file
the compiler does not over-write that file
just know that the def file has to exist, even if it's empty
Title: Re: Resource compiler problem
Post by: mike2 on August 08, 2011, 01:56:42 PM
And one more time:

The file called resource.h is no common include file, but project specific. Every time I save the file rsrc.rc in the resource editor, the file rsrc.rc gets overwritten since it is saved and the file resource.h gets overwritten since it is autogenerated each time I save the project.

But using H2ASH in the makefile solves this problem, since it will convert the "#define" syntax to "equ" syntax which can be included as resource.ash in the ASM code.

@hutch--:
My resource editor always uses equates when working with *.rc files. For example, IDD_EDIT2 is always valid and points to the same item, while its ID might be 1003 after one save and 1007 after the next time saving. I could use numbers and *.res, but I find it more comfortable to use more "readable" constants.
Title: Re: Resource compiler problem
Post by: hutch-- on August 08, 2011, 03:00:32 PM
Mike,

It sounds like if your build environment cannot be adjusted to work with resource.h and will only work with equates in C format, you need some other mechanism to construct the assembler equates as the two forms are incompatible. Where I have to use resource compilers that mess around with the RC file, I use the RC notation to "#include" problematic RC files so they can be edited by themselves without messing up the rest. RC.EXE supports the "#include" directive.

I doubt there is an automatic method around if you resource ID numbers keep changing, somewhere along the line you will need to do the conversion from the C format to ASM format, perhaps write yourself a parser that will do that if your build environment is so inflexible.
Title: Re: Resource compiler problem
Post by: Gunner on August 08, 2011, 04:48:16 PM
The resource editor in radasm and probably the standalone resource editor from keitlo, allow you to export as equates
Title: Re: Resource compiler problem
Post by: dedndave on August 09, 2011, 02:51:38 AM
ok - the IDE gets the resource.h file from someplace !!!!!
i sincerely doubt it is embedded in the EXE
add your #include to that
Title: Re: Resource compiler problem
Post by: mike2 on August 09, 2011, 08:18:47 AM
I don't want to sound unthankful, but I already wrote that (and how) I solved my problem 7 posts ago.

I have no idea why I always should mess with the *.h include files since the resource compiler understands #define. I could #include a million other *.h files and still not a single one would bring me even one step closer to the problem I asked here in the first place.
Title: Re: Resource compiler problem
Post by: hutch-- on August 09, 2011, 08:44:06 AM
Mike,

I am please to hear that you have solved your problem but issues that have been addressed are a bit wider than the specifics of how you have ended up solving your own problem. I have been using deviant resource editors since before 1990 and many have unusual quirks that were designed to suit the environment they were provided with but RC.EXE has worked much the same way for the last 20 years or so and it is generally the reference, not a resource editor. RESOURCE.H as a collection of equates for resource types is an old standard and while I have had resource editors that deviated from this in the past and wrote their own, they deviate from the historical standard.
Title: Re: Resource compiler problem
Post by: mike2 on August 11, 2011, 08:02:58 AM
I think we can definitely say that today not RC.EXE is the de facto standard for Windows programming but Visual Studio. All Windows C++ developement environments developed in the last 15 years (or even more) have the resource equates located in "windows.h" (#include winuser.h)

But no matter how this *.h file is called, it is - forgive my words - total bullshit to edit any global include files and to insert application specific constants there.
Title: Re: Resource compiler problem
Post by: dedndave on August 11, 2011, 11:09:47 AM
perhaps the best thing you can do is to look for a different IDE