I highly recommend you to write applications in Unicode. Unicode improves the efficiency of your application because the code performs faster. That sounds really sneaky but it's true. Windows internally does everything with Unicode. When you are passing an ANSI string or character, windows must allocate memory and convert the ANSI char/s to it's Unicode equivalent. There are a lot more reasons why you should use Unicode like ensuring that your application can easily call all nondeprecated Windows functions... Well, in our time there is no really need to think about that (in most cases) but that was just a small quick tip from my side ;)
Recently I took a short look on your thread management which provides CreateThread and TerminateThread. Don't use it! Have a look on this "virtually" short quote:
Quote:
|
Originally Posted by Windows System Programming 4th Edition
Most code requires the C library, even if it is just to manipulate strings. Historically,
the C library was written to operate in single-threaded processes, so some functions
use global storage to store intermediate results. Such libraries are not thread-safe because
two separate threads might, for example, be simultaneously accessing the library
and modifying the library’s global storage.
The function strtok is an example of a C library function that is not threadsafe.
strtok, which scans a string to find the next occurrence of a token, maintains
persistent state between successive function calls, and this state is in static
storage, shared by all the threads calling the function.
Microsoft C solves such problems by supplying a thread-safe C library
implementation named LIBCMT.LIB. There is more. Do not use CreateThread;
if you do, there is a risk of different threads accessing and modifying the same
data that the library requires for correct operation. Instead, use a special C
function, _beginthreadex, to start a thread and create thread-specific working
storage for LIBCMT.LIB. Use _endthreadex in place of to ExitThread
terminate a thread.
Note: There is a function _beginthread, intended to be simpler to use, but you
should never use it. First, _beginthread does not have security attributes or flags
and does not return a thread ID. More importantly, it actually closes the thread
handle it creates, and the returned thread handle may be invalid by the time the
parent thread stores it. Also avoid _endthread; it does not allow for a return value.
The _beginthreadex arguments are exactly the same as for the Windows
functions but without the Windows type definitions; therefore, be sure to cast the
_beginthreadex return value to a HANDLE to avoid warning messages. Be certain
to define _MT before any include files;
|