News:

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

Resource compiler problem

Started by mike2, August 07, 2011, 03:24:34 PM

Previous topic - Next topic

mike2

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.

dedndave

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

dedndave

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

ToutEnMasm

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.

mike2

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.

ToutEnMasm


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

mike2

#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.

ToutEnMasm


The result is the same.You couldn't begin any word by #.

dedndave

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

Tedd

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
No snowflake in an avalanche feels responsible.

dedndave

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:

mike2

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

hutch--

Mike, I keep the world simple with resource scripts, I use numbers directly with no equates.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

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

mike2

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.