wmain vs _tmain

Wednesday, April 18th, 2007

Once again I find myself awake at 1:00am perusing my site access logs. Tonight I noticed something particularly interesting.. a decent number of people coming to my site visited the site in reference to the search query “wmain vs _tmain”.

Being the helpful individual that I try to be, I have decided that since so many of you are reaching my site from these terms, that I may as well provide a short and sweet answer to the question.

What is wmain, what is _tmain, and how do they relate?

Every C/C++ programmer I know is familiar with the main() function. This function being, of course, the entry point into your C or C++ application.

Much like main, wmain is also an entry point into your application it differs only in that it is the wide character version of this entry point. So if you wanted to support unicode in your application, it would be wise to use wmain for parsing of command line arguments and environment variables. It is important to note that the wmain unicode entry point is Windows specific.

Finally, _tmain is a Windows specific #define defined in TCHAR.h header file. This define resolves to wmain if UNICODE is defined, or the classic main() if UNICODE is not defined.

And now your search is no longer futile. Enjoy wandering C/C++ programmer. I hope I have helped.

Source: http://msdn2.microsoft.com/en-us/library/6wd819wh(VS.80).aspx

My First Adventures in Windows Land

Thursday, December 14th, 2006

It’s been years since I was given the gift of my first compiler by my parents.

It’s been almost as long since I’ve experimented with the Windows API.

Shortly after receiving the gift of Visual Studio 6 I made the switch to Linux as my desktop operating system of choice. Unfortunately this left me with minimal experience with windows programming. To this day the majority of my programming projects and tasks have taken the form of simple 2D graphics engines using SDL, or simple form based applications using QT or GTK+.

Until recently I had always felt like I was missing something, I never had the most basic experience developing applications for the Windows operating system. This always left me with a bit of a pit in my stomach, as I didn’t have the funds required to purchase a copy of Windows, purchase Visual Studio, and begin my experiments anew.

Thankfully I was very recently offered a paid internship position with a company called Railcomm Inc. At Railcomm I was given the opportunity to develop some Windows programming skills. I developed screen after screen of graphical Windows application with relative ease. I considered myself at least a successful basic Windows programmer.

At the start of this project I figured setting up a Window to contain my DirectX 9.0c rendering context would be simple as pie. “It’s only a few function calls” I had been told over and over again. I was sure I’d have no problems at all.

Boy was I wrong.
What follows are the steps I used to learn to develop a “simple” Windows application.

(more…)