News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Preprocessor/Macro Constant

Started by ragdog, February 28, 2018, 05:45:01 AM

Previous topic - Next topic

ragdog

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,

HSE

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.
Equations in Assembly: SmplMath

jj2007

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

ragdog

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,

sinsi

The macro itself is fairly straightforward but masm chokes if you call it #define
Doesn't seem to like the # character.

hutch--

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.