Creating a Windows Service in Visual Studio

In earlier versions of Visual Studio there was a template to create Windows Service in C++ by going to File menu -> New and clicking on Project. In the New Project dialog, if we click the Visual C++ Projects node in the Project Types pane, there was a Window Service template. This is not available in Visual Studio 2010. The C++/CLI template for creating Windows Services was also removed. Only the C# template is available if you want to use managed code to develop Windows Services. If you need to create a Windows Service in unmanaged C++, your option is to use ATL.

In the new Project dialog, under Visual C++, click on ATL and select ATL Project in the center pane. Enter the name of the project and click Ok button.


This displays the ATL Project Wizard. Click on the Next button.


In the Application Settings, select Service (EXE) as the Application type and click Finish. Now Visual Studio will generate the required code files to get you started on developing a Windows Service.


However, there is one gotcha.

When you build the solution that you just created you will (most probably) get an error:

Error    1    error MSB3073: The command “”<path to Atl.Service.exe>” /RegServer :VCEnd” exited with code -2147024891.    C:Program FilesMSBuildMicrosoft.Cppv4.0Microsoft.CppCommon.targets    113    6    Atl.Service

Not a very useful error message. And I was a little confused because I was building the template created by Visual Studio, I didn’t make any modifications to it. Was Visual Studio shipping templates that won’t compile ? It turns out that the problem was that Visual Studio was not running as an administrator. Once you close Visual Studio and restart it to run as an Administrator, you will not the see this problem anymore. The project will build fine.

Happy coding.


Free online course on Artificial Intelligence conducted by Stanford

Stanford is conducting a free online course on Artificial Intelligence taught by none other than Peter Norvig and Sebastian Thrun. There are 2 tracks – basic and advanced. If you don’t have time for the assignments and exams take the basic track. You can switch between the tracks any time. You will receive a statement of accomplishment signed by Sebastian Thrun and Peter Norvig.

The course is from Oct 10th to Dec 18th.

Here is the website for the course. Course overview is here. You can enroll here. Course schedule is here.

Welcome 2011

I have had quite a few resolutions for 2010. Now I hold my head high and tell you all – I didn’t do even one of them 🙂

While that speaks volumes about my nature, I wouldn’t want you to think I am quitter. I have more resolutions for this year.

  • I will reduce my weight by 15 lbs. I weigh 185 lbs now, so by Dec 2011 I expect to be 170 lbs. I haven’t been 170 lbs since some time in 2002. Now I expect to be back at that weight by 2012.
  • I will reduce my cholesterol to normal values. Now I am grossly over the normal values (total cholesterol = 300)
  • I will greatly increase my knowledge on algorithms and data-structures. This is a vague one. But that’s OK. Any progress in this direction is good for me.
  • I will study discrete mathematics. This is also quite vague but my intention is to be a little less clueless than I am now.

That is it friends. Just 4 things. Let us see how that goes.

A Learning Project

Binil and I have decided to study Computer Systems: A Programmer’s Perspective together. We are going to use the first edition because we both already own that and the 2nd edition is damn costly. Binil is in California and I am in Washington, so it is going to be a long distance combined study. We imagine this would take up the rest of this year, and even then it will be a challenging task (because we intend to do the exercises as well).

One of the challenge would be to maintain the interest in the project. I usually lose interest in any book after reading about 100 pages or so and this book is a little over 900 pages. We have decided that one should help the other maintain the momentum, motivation and interest. Another challenge is that (as I mentioned earlier) we are not in the same location. We decided we would communicate through email during the weekdays and have a telecon on the weekends. We should be able to fine tune the process as we go along. We also expect other challenges to show up as we go along but failing halfway would be better than not doing it at all (this pearl of wisdom may not apply to everything, so reader discretion advised).

For the first week, starting today, we will attempt to read the first chapter (there are no exercises in the first chapter).

P.S. One of the reasons for making this blog post is that making our commitments public will give us more motivation and inspiration to complete it or at least stick with it for a longer period than otherwise.

Slow down or pay up

As I was driving to office today I noticed a message on the freeway warning board – “Slow down or pay up”. I find these warnings tasteless. The tone is offensive, just like the more frequently seen “Click It or Ticket”. That tone might works for kids but with adults I can imagine the response to such warnings to be “Fuck You”. In my opinion something more appropriate would “Please slow down for your own safety” or “Please slow down for the sake of everybody”.

P.S. I am not against keeping the speed within limits on the road, I am just saying that the message should be friendly. I could be wrong in my assessment because the “Click It or Ticket” is America’s most successful seat belt enforcement campaign creating a seat belt usage of 83%. On an unrelated note, 58.7% of statistics are made up on the spot.

Starbucks Economics

I am not a big Starbucks fan but today afternoon I was a little bored and I thought I would go for a walk and have a coffee at Starbucks on the way. I had a Chai Tea Latte and including the tip the total came around to $4. I found it a little bit difficult to digest that a cup of tea can cost so much and that quite a lot of people doesn’t seem to mind. From where I come from (India), $4 will buy you about 40 cups of tea (yeah, I know it is not a fair comparison).

Starbucks is not the only place where I find that people are overpaying without complaint. Just drive by any wealthy neighborhood and we find shops and boutiques waiting for their wealthy preys. When I find myself in such circumstances (i.e. goods being sold at a price seemingly more than what it deserves) I usually get a little stressed and angry at the system – “Let us boycott this and teach them a lesson”. But when I thought more about it today (sitting at Starbucks and drinking their latte) I think I was being totally stupid. Nobody should lose any sleep over this.  Such a system can thrive only when a reasonable number of people are willing to buy from them. Otherwise they will have to close down. The simple fact that Starbucks is thriving means that many people think that the coffee (and the environment) is worth the price. Why somebody would pay $4 for coffee is something that I might never understand but I felt a lot more comfortable, a lot more Zen, when it dawned on me that the system is self balancing. No war is required !

P.S. I hate it that Starbucks have a “Small” size but they never advertise it on their menu, I think it is a sleazy tactic.

ClickOnce Installation for Multiple Users

An interesting question came up in one of the internal mailing lists at work about ClickOnce. The person who asked the question had the following scenario for his ClickOnce application.

The application runs in a call center. Assume there are 100 users and 100 computers. Any user can use any machine on a given day. Assuming everyone uses a different machine each day for 100 days then each day they will have to install the application on the machine they are using and by the 100th day each machine will have 100 installations of the app. Clearly not a desirable situation.

How do we go about solving this ?

The quick answer is that you cannot solve it using ClickOnce in a straightforward manner. The reason ? ClickOnce installations are always per user. It is by design and not a side effect or even a configurable option. When you install a ClickOnce application it goes into C:Users<User>AppDataLocalApps2.0<Blah>. Here <Blah> is a set of folders with names that doesn’t make much sense. For example, here is an actual example of the full path to a ClickOnce installation – C:Users<User>AppDataLocalApps2.08Y7PD2RC.9VEL1OL139M.4W2. These names would be different on different machines. This makes it very hard to find the location of the installation, so we cannot share the installation between users (assuming that other users have access to this folder). Other users would not get desktop shortcuts and Start->Programs shortcuts. Also AppData is a hidden folder which makes it even harder to find for non-technical users.

So what do we do ?

For the specific scenario here, ClickOnce does not fit the bill as the deployment strategy. MSI is a better choice. XCopy might also work depending on the application requirements.

Raymond Smullyan Books

As I mentioned in my previous post, I made an impulse purchase of 7 books by Raymond Smullyan from Amazon. Six of them arrived today, the remaining one book is not published yet. Here is the list of books that came today:

The remaining book is Set Theory and the Continuum Problem.

Raymond Smullyan is a remarkable man. He is a magician, mathematician, logician, concert pianist, philosopher and world renowned author of over 20 books. Some Interesting Memories: A Paradoxical Life is his autobiography and there is a film about him called This Film Needs No Title created by documentary filmmaker Tao Ruspoli. Smullyan is 90 years old now and lives a “retired life” in the Catskill Mountains in NY.

If you haven’t read any books by Smullyan I recommend that you get a couple of them from the library and give it a try. I am sure you won’t regret it.

The battle to lose Stuff

As I mentioned in a previous post, I am trying to minimize the “stuff” in my life. It was something that I have been wanting to do for a little while now, but the decision to go ahead with it came after reading The Power of Less , by Leo Babauta, the second time. The first time I read it, I found the concept attractive and in sync with my thoughts. But I got distracted and I forgot about it. I came across it after later while I was browsing the library and this time I decided to atleast give it a try. As the first step I gave away quite a few of my books. I also sold some on Amazon. It wasn’t much compared to what I had but still it was a good start. Then I gave away many clothes and shoes with I don’t use anymore. It felt good on two levels – the joy of giving as well as being able to get my foot in the door of a new way of living.

I am ashamed to say that I made a splash starting from last Friday. I bought 2 new books from Borders on Friday. I had a copy of one of them from the library but I still wanted to have my own copy. I rationalized that this was a book that requires multiple readings and that it was a very good book and worth owning. I am still not sure whether this a good move. The 2nd book was one that I really wanted to get but considering my current situation I don’t think I would be able to get to reading that book for the next 6 months. Maybe I should have waited to see whether I would actually get time to read it.

On Sunday we went to Seattle Premium Outlet Mall in Tulalip and I bought quite a few new clothes. The primary reason we went to the mall was to get a pair of sunglasses for Rija and maybe some new clothes for her. When we were done, I had bought more clothes than Rija and also a pair of shoes. I have lots of clothes, I didn’t need to buy any new clothes but I gave in to the shopper’s impulse and as a result I have increased my Stuff. I am not very proud of this incident.

On Monday I was browsing through Amazon (I should really stop browsing through Amazon) and I stumbled on Set Theory and Continuum Problem by Raymond Smullyan. I thought this would a good book to buy as I had read other books by Smullyan and I have great respect for him. Also Binil had convinced me that learning some maths is good for anybody. The book was not expensive so I didn’t give much thought about it and decided to go ahead and buy the book. While ordering the book, Amazon showed me other books by Smullyan and I fell for end. All said and done I ordered 7 books. 7 books ! I am not sure whether I would ever get to read them, but I had to order it. Some part of me just craved for the transient high of obtaining new Stuff.

To top all this, yesterday we went to Walmart to get some medicine for Rija and I ended up with 3 new shirts ! How bad am I ?

Actually the books that I bought are very good and it will surely be fun and beneficial if I ever read them. The clothes that I bought are good and I look forward to wearing them. But did I need these ? I don’t think so.  I could have bought the books when I have the time to read them and I could have bought the clothes when I have worn out my existing clothes or given them to the needy.

I have to be more aware of my thoughts, emotions and impulses. I should avoid the temptations if I can’t resist them. My first steps faltered, but I am not giving up. I am going to try my best to minimize the Stuff in my life, instead I am looking forward to experiencing more of life’s little pleasures such as spending more time with friends and family, going for walks, playing games, long drives with my wife, visiting places, etc. In general enjoying the experience of living rather than that of having.

The Checklist Manifesto – Book Review

This is a review for The Checklist Manifesto: How To Get Things Right (Hardcover) by Atul Gawande.

Dr.Atul Gawande is one amazing dude. Let us deviate for a moment to see what his biography on the book sleeve says:

Atul Gawande is the author of The Checklist Manifesto, Better and Complications. He is also a MacArthur Fellow, a general surgeon at the Brigham and Women’s Hospital in Boston, a staff writer for The New Yorker, and an assistant professor at Harvard Medical School and the Harvard School of Public Health, he also leads the World Health Organization’s Safe Surgery Saves Lives program.

How can one person do all that ? He must be The Dude.

I haven’t read Better and Complications but both books have good reviews on Amazon. However, The Checklist Manifesto falls short of expectations set by the author’s previous achievements. The reason for this is that the book’s message is really thin – checklists are good, they can even save lives. The book is full of anecdotes from the author’s life. It is fun to read those anecdotes but in the back of my mind I kept looking for the author’s insight into creating a good checklist or a sample of one he made or any other kind of advice. But the book just kept on making cases to prove that having a checklist is good and they work (especially in the context of medical profession).

One of the strength of the book is the excellent writing style of the author.

Tangentially this book is an eye opener regarding the working of the surgery room and emergency room in hospitals. Things could go wrong in hundreds of ways. Dr.Atul sums it up very well in his book with this:

we (medical care professionals) are as apt to harm as we are to heal

I also respect him in writing about a surgery he did when the patient almost died because of his “fault”. It requires great strength to admit one’s mistake.

Bottom line is that this book is worth reading for people in medical profession (although checklists could useful in a lot of other situations, this book is probably most useful for medical professionals). I would rate the book 3 out of 5 and would recommend reading Better and Complications.