Post by mshettyHi,
When you have a CreateMutex what is the use of CreateMutexW and
CreateMutexA?? Are they available only for specific platforms?? Where
can I get more information on this??
MSDN only talks of CreateMutexW. It says
"CreateMutexW is supported by the Microsoft Layer for Unicode." on
platforms
Windows Me/98/95.
Couldn't find any mention of CreateMutexA.
Whenever you have functions like FunctionA() and FunctionW(), it means
that one supports single byte strings where needed and the other
supports double byte (unicode) strings.
Notice that for CreateMutexA() the last arcgument is an LPCSTR where as
for CreateMutexW() the last arg is LPCWSTR.
Also notice that in the docs for CretaeMutex() that the last arg is
LPCTSTR.
But CreateMutex() is not really a function in the 32bit Windows
libraries/dlls. It is a fake that was #define'd depending on whether or
not you have UNICODE #define'd during your build. For example, from
WinBase.h:
#ifdef UNICODE
#define CreateMutex CreateMutexW
#else
#define CreateMutex CreateMutexA
#endif // !UNICODE
The type LPCTSTR (and also LPTSTR) are also #define'd depending on
whether UNICODE is #define'd at build time.
When UNICODE was defined, then CreateMutex() is actually CreateMutexW()
and LPCTSTR is actually LPCWSTR. If UNICODE wass not #defined then
CreateMutex() is actually CreateMutexA() and LPCTSTR is LPCSTR.
All of the Windows OSes based upon the NT core (NT, 2000, XP and 2003)
use Unicode internally for all their internal data and thus system calls
(opening filesm created locks, etc...) need to be done with Unicode
strings. Any single byte strng string versions of these system calls are
just wrappers which convert the string to Unicode before claling it.
The Windows 9x (95, 98, ME) do not use Unicode internally which is why
the NT-based Windows have the single-byte wrappers so they can run
programmes written for the Win 9x group. Now there is the MS Layer for
Unicode for the Win 9x group, but unfortunately it is not a full
implementation.
Without the Function()/FunctionA()/FunctionW() #defines mentioned above,
you would have to maintain two different sets of code for programmes
that ran on both the 9X broup o rthe NT-based group. Or, at the very
least, have scads and scads of #ifdef/#else/#endif throught out your
code to compensate for the limitations of the 9X group. Hairy, to say
the least. But if you use data types like LPCTSTR/LPTSTR instead of
LPCSTR/LPSTR or LPCWSTR/LPWSTR, and Function() instead of FunctionA() or
FunctionW(), then you don't have to worry whether or not a you need to
use a Unicode or non-Unicode function, 99.9% of all those confusing
#def/#else/#endifs are gone, and and with the same code you can have a
programe that runs on the limited Win9X group and you can use the full
Unicode capabilities of the NT-based group.
Not only does it help to maintain code for platforms with different
capabilities and needs, but it also allows for a programmer, used to
coding in the single-byte string, codepage world of Win9x to retain all
their knowledge and skills WRT Windows programming and move easily to
the Unicode universe. It also makes it easier to upgrade programmes to
support by changing all char data types to TCHAR, compiling to make sure
everything still works, then #defining UNICODE, recompiling and changing
the few places where necessary (like changing calloc()s for allocating
string space to include sizeof(TCHAR)).
If all of this is still confusing for you, compare sprintf(), swprintf
and _stprintf() and take a look at tchar.h.
--
Cory Albrecht
http://www.sentex.net/~corya/