The MASM Forum

General => The Campus => Topic started by: ragdog on February 28, 2018, 05:45:01 AM

Title: Preprocessor/Macro Constant
Post by: ragdog on February 28, 2018, 05:45:01 AM
Hello

I have a question to use a one constant string in Asm and RC files?
In Cpp can i use a include like this

Constant.h
#define ConstString "abcd"


Rc file
#include "Constant.h"

some code ConstString


In C/Cpp file to

#include "Constant.h"

int main(int argc, char* argv[])
{
      printf("My const string is: %s " ConstString "\n");


Is it possible to write a macro to convert the #define

#define   ConstString "abcd" 

to

ConstString db "abcd",0

and use it in Masm code?

I know #define give error by compile but is there a solution?

Regards,
Title: Re: Preprocessor/Macro Constant
Post by: HSE on February 28, 2018, 10:58:25 AM
Hi Ragdog!
I think You can replace #define with STRING using some editor, like RadAsm. But you have to add a coma manually after string's name.
Title: Re: Preprocessor/Macro Constant
Post by: jj2007 on February 28, 2018, 01:21:31 PM
include \masm32\include\masm32rt.inc

MyData equ <"Hello World">

.data
HelloW$ db MyData, 0

.code
start:
  MsgBox 0, offset HelloW$, "That was easy!!", MB_OK
  exit

end start
Title: Re: Preprocessor/Macro Constant
Post by: ragdog on March 02, 2018, 08:15:23 AM
Hello

@HSE yes i know i can use a editor to replace but this is not my goal
@Jochen too

I ask it is possible to use a macro to change it.

Thanks you both for reply

Regards,
Title: Re: Preprocessor/Macro Constant
Post by: sinsi on March 02, 2018, 09:34:39 AM
The macro itself is fairly straightforward but masm chokes if you call it #define
Doesn't seem to like the # character.
Title: Re: Preprocessor/Macro Constant
Post by: hutch-- on March 03, 2018, 04:55:01 AM
I would be inclined to think that,

#define   ConstString "abcd"

would become

ConstString equ <abcd>

  or

ConstString equ "abcd"


Without looking it up, perhaps a TEXTEQU.