December 11, 1999

18 Common Programming Traps in MTS

icrosoft Transaction Server (MTS) is certainly not new, but there are still a lot of common design and programming errors being made. In this article I will show you 18 examples of such errors (together with proposed solutions). A few of the problems will lead to erroneous results and others

Determine the Windows version (without any API call)

You can use the GetVersion or GetVersionEx API functions to determine which Windows version the application is running on. However, there is a much simpler solution, based on the fact that Windows NT creates an environment variable named “OS” while Windows 95/98 don’t. So you can quickly discern between Windows

Get login information the easy way (without any API call)

While you can use many different API function to get user and domain information, if you’re running under Windows NT or 2000 Server there is a shortest path, based on the fact that the operating system loads many piece of data into environment variables: ‘ this code works only under

Get the Windows temporary directory (without any API call)

The usual way to determine the Windows’ main directory is based on the GetTempPath API function, which requires that you set up a buffer for the result, and then extract the null-terminated result. However, there is a much simpler approach, that works equally well under Windows 95, 98 and NT.

Retrieve CPU information the simple way (NT/2000 only)

The Windows API includes all the functions you need to retrieve and display information about the CPU the machine is equipped with. However, if you’re running under Windows NT or Windows 2000, you don’t need to make complicated API calls, because this information is already available in several environment variables,

Get the Windows main directories (without any API call)

The usual way to determine the Windows’ main directory is based on the GetWindowsDirectory API function, which requires that you set up a buffer for the result, and then extract the null-terminated result. However, there is a much simpler approach, that works equally well under Windows 95, 98 and NT: