.NET vs Native Win32 code

Ok so I've been writing apps using C# for a couple of years now. I had done some work in MFC but not much. Mostly console stuff very little GUI work. Well I recently thought how hard could it be to work in win32? The answer is mixed of course. I should give some background on how this came about. I recently published a ip viewer tool written in C# that monitors your ip address. It sits in the system tray and when double clicked shows a dialog form. It took me about 8 hours of coding to put together. It runs and works and does its job well. However it takes the .net framework v2 which as much as MS wants to say isn't standard on pc desktops across the world yet. And while it's not slow, on first load it sure as hell ain't fast. After first load it's pretty snappy but damn it looks like hell until it does. And this app isn't very large a 72KB exe is all. 3 forms and 1 support dll that really could be in the exe.

So I decided to write the exact same thing in native win32 code. I dug up some tutorials on the internet and away I was. Man at first I was in a world of hurt. It took me about 3 days to get a version that would get the ip address, check on intervals, and sit in the system tray with the correct tool tip. It doesn't have as much functionality as the C# version but it's close. It was hard at first, damn hard. I don't think I wrote more code but the type of code was certainly different.

So what are my opinions of both types of coding after all this? Mixed, of course! C# is very easy to code in. The ease of use and amount of controls makes doing any windows task very easy. Of course this comes at a cost. My .net app runs using 12 MB of ram. 3 forms and 1 DLL that is a huge amount of RAM for such a tiny app. My win32 version takes less then 3 MB of ram. And the lag is non-existent in the win32 version. It's responsive from the get go and runs great. But it was harder to code. There is a lot less built in support for win32 code. You really have to be familiar with the api and have a good knowledge of the structures they use. The win32 api is a mess as far as I'm concerned. So what does this mean? Pick the right tool for the job. And that is subjective for each programmer/task. Use the best tool that gets the job done for you. Just realize each way of doing things has its trade-offs. For my recent project if I knew the win32 API beforehand would have been much easier. After looking back I think for this particular project it's a wash. The C# version was a ton easier to code but runs a bit slower. The win32 version was a lot harder to code but runs much leaner.


Update: I almost didn't want to do this but after a comment was made I feel I need to expand this just a bit. No it didn't take 3 days to get an IP address. That part is easy. It took 3 days to learn the win32 API and create a true win32 application that behaved exactly like a C# application. And like I said in the post maybe if I knew more of the win32 API this wouldn't be such a big deal.

Comments

kiyu727 said…
Thanks a lot, this article showed me the small yet great wall between C# & C++.
Even though the article is a bit old.

Popular posts from this blog

String.Replace vs Regex.Replace

C# Form Application in Kiosk Mode/Fullscreen

C# using a transaction with ODBC