www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - C Macro to D

reply a.c.edwards <a.c.edwards_member pathlink.com> writes:
What is the proper way to convert this C macro to D?

:  #define TEXTVIEW_CLASS _T("TextView32")

This is how I understand it, but don't know if it is correct:

:  const char[] TEXTVIEW_CLASS = "TextView32";

am I way off base here?

Thanks,
Andrew
May 27 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"a.c.edwards" <a.c.edwards_member pathlink.com> wrote in message 
news:d773c7$1ga7$1 digitaldaemon.com...
 What is the proper way to convert this C macro to D?

 :  #define TEXTVIEW_CLASS _T("TextView32")

 This is how I understand it, but don't know if it is correct:

 :  const char[] TEXTVIEW_CLASS = "TextView32";

 am I way off base here?

Nope, that's about right, though that particular string would only be usable with the A versions of the API functions. If you'd like to use the W versions, you'd have to use a const wchar[]. Or, you could have a version statement: version(Unicode) { const wchar[] TEXTVIEW_CLASS="TextView32"; } else { const char[] TEXTVIEW_CLASS="TextView32"; } Which is essentially what the _T() macro does in C. You could also use the version(Unicode) statement to make aliases for the W versions of the functions (like MessageBoxW to MessageBox), and in the else, alias the A versions. That way, you can just put a -version=Unicode on the compiler commandline (or leave it out), and the correct set of functions and constants will be selected. :)
May 27 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Jarrett Billingsley wrote:
<snip>
 Or, you could have a version statement:
 
 version(Unicode)
 {
     const wchar[] TEXTVIEW_CLASS="TextView32";
 }
 else
 {
     const char[] TEXTVIEW_CLASS="TextView32";
 }

Or have somewhere version(Unicode) { alias wchar TCHAR; } else { alias char TCHAR; } then you can do simply const TCHAR[] TEXTVIEW_CLASS="TextView32"; a little less repetitive when you've got lots to declare. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 02 2005