Quick question: I'm converting an .h file from the MS SDK that isn't already in the windows.inc and I'm seeing a log of
#ifdef UNICODE
#define HtmlHelp
#else
#define HtmlHelp
#endif
I'm keenly aware of what's going on here, what I'm not aware of is how to accomplish the same thing in assmebly? Based on whether or not unicode is supported on the platform I run my program on which uses this help file, how can I conditionally support UNICODE?
I do not know if MASM preprocesses these sort of things, but I can assume I can check the presence of NT/2k, or perhaps some api that tells me if Unicode is present. From there, in masm, how can I conditionally set to the proper export?
Thanks
Two unfortunate facts of life:
1) MASM has no built-in support for Unicode. Unicode is too high a level abstraction to affect how code is assembled.
2) The MASM32 package is mostly blank when it comes to Unicode. Typically, .h files will change say "MessageBox" to "MessageBoxA" or "MessageBoxW" depending if you declared UNICODE or not.
MASM32 will simply flip "MessageBox" to "MessageBoxA" It does not even define "MessageBoxW"
That being said, adding Unicode to your app isn't the worst thing in the world. You would have to re-work the include files, which would mostly be a copy and paste proposition.
Also you need a way to define a Unicode text string. Two ways here, as the following generates a legal Uni string:
wszText WORD "A"," ","W","i","d","e"," ","S","t","r","i","n","g", 0
; ("A Wide String")
If you don't mind they change of typos, you may do that, or write a macro to do it for you (see "L.inc" in the new masm32\COM section: It contains this macro).
Also, the API defines MultiByteToWideChar and WideCharToMultiByte functions.
My htmlhelp.inc file looks something like this (in addition to 500 lines of constands and structures definitions -- hand converted):
HtmlHelpA Proto,:DWORD,:DWORD,:DWORD,:DWORD
HtmlHelpW Proto,:DWORD,:DWORD,:DWORD,:DWORD
HtmlHelp
In psuedocode, I want
Indicator := Unicode_Supported
If Indicator == Yes Then
HtmlHelp
Else
HtmlHelp
Two ways to approach this:
1) A macro that detects whether UNICODE is supported and then places the results in some sort of flag. I could then use that flag to determine how to define
2) A macro that detects unicode support and then defines HtmlHelp itself -- much much more reuasable than the previous. Except I would have to still retain a flag since I would conceivably have 100's of other Wide API's.
My specific question would probably be something like: How do I detect UNICODE support in MASM? Are there API's for this? Or how... somehow there must be a way, since other compilers do this nicely.
Thanks,
Shawn
Hmm... no angle brackets... here's a translation:
-------------------------------------------------
My htmlhelp.inc file looks something like this (in addition to 500 lines of constands and structures definitions -- hand converted):
HtmlHelpA Proto,:DWORD,:DWORD,:DWORD,:DWORD
HtmlHelpW Proto,:DWORD,:DWORD,:DWORD,:DWORD
HtmlHelp
In psuedocode, I want
Indicator := Unicode_Supported
If Indicator == Yes Then
HtmlHelp
Else
HtmlHelp
What you need is a good dose of conditional compilation:
.code
UNICODE EQU 1 ; optional line
{in .inc files}
HtmlHelpA Proto,:DWORD,:DWORD,:DWORD,:DWORD
HtmlHelpW Proto,:DWORD,:DWORD,:DWORD,:DWORD
IFDEF UNICODE
HtmlHelp EQU HtmlHelpW
ELSE
HtmlHelp EQU HtmlHelpA
ENDIF
This gives you all possibilities, simple default cast to UNI or ASCII, or you could reference HtmlHelpA in a Unicode program if you needed such.
Please note I did not forget dots on the IF, ELSE and ENDIF. These statements work as compilation macros without dots.