tags:

views:

1295

answers:

17

I was certain that somebody would have specifically asked this question, but from what I can see no-one has (there's been a question about learning win32 but that doesn't cover whether it's worthwhile doing so).

I am very interested in gaining a deeper understanding of all the systems I use (I mostly program in C#, at least professionally), so I wondered, very simply - is learning win32 worthwhile, or is it overkill? Am I wasting my time? Is the knowledge I'd gain worth the effort?


Similar / related questions on StackOverflow:

Does it still make sense to learn low level WinAPI programming?
How relevant is Win32 programming to modern professionals?

+2  A: 

If you are trying to write a VB6 application then the Win32 API allows you to do a lot of things that are not natively supported by VB6.

If you're writing a C# WinForms app then I would recommend learning the vast reaches of the .NET Framework first.

Edit

If you really want to know what's going on under the hood in Windows then you might want to check out a copy of Programming Windows 3.1 by Charles Petzold.

Richard Ev
I already have a pretty good (well given the huge vastness of the .net framework it's all relative) working knowledge of WinForms, but of course that's a leaky abstraction and I have no real depth of knowledge of the 'under the bonnet' workings of the library...
kronoz
An abstraction - yes, but also known as a more consistent and usable API. Leaky...I hope not!
Richard Ev
+2  A: 

I personally think it's still worthwhile learning the Win32 API.

As far as I recall when I started learning Win32 (after doing some VB(A), Pascal, etc.) I learned a lot about Windows and understood how thing works in Windows. Everything was so clearer. :)

So, as per your question - you will learn a lot about Windows through learning Win32. As you said - your a C# programmer and I'm not sure if you'll use it often, because almost everything you need is already there, in .NET.

emirc
+13  A: 

Having an working knowledge of how Win32 works at the lowest level will certainly be invaluable if you are planning on doing windows development in the future. It gives you a level of insight into things like Windows, Messaging and GDI that are hidden by the time you get to the level of .NET.

I wouldn't recommend you try and use Win32 for writing all your applications, but I feel that any Windows developer would benefit from writing a simple Win32 application using C/C++.

This is less true for things like WPF where there is less dependency on Win32, but just knowing how Win32 works will help you understand or appreciate some of the design decisions in WPF.

Andrew Grant
Sure, and of course I'd only be interested in using it where necessary.
kronoz
@Andrew Grant: I completely agree - since so much of the .NET library is Win32 based, I often find myself understanding their design choices much quicker when I remember that in many cases they're just wrapping the underlying Win32 APIs.
Mike
+6  A: 

At least for me, learning an API (I'm assuming that "in-depth" is implied) that I don't use is a waste of time. I'd rather spend my limited amount of time and brain power learning new concepts or exploring new tools than becoming intimately familiar with an existing tool that I don't need to use now. When I need a particular tool that I don't have or have to use a tool that I'm not familiar with, that's the time to learn it in some depth. Before that I might do enough investigation to know whether it is going to be useful to me or not, but not much more.

tvanfosson
+1  A: 

You'll never be able to just "learn" the entire win32 API, it's too much to take in, and it will be a moving target. If you develop in C#, there's no real point.

That said, try creating Notepad using plain C and just API calls. That will teach you enough for a C# developer to at least appreciate it.

ste
of course I don't imagine I could know all of win32, what I mean is to learn a good subset and get a working knowledge going. Your idea is interesting, sounds like a good project :)
kronoz
+8  A: 

I advocate learning the concepts behind low level windows programming if all of the following are true.

  1. You are going to do any windows programming.
  2. You want to be the "go to" guy when the unexplainable happens.
  3. You love to learn.

Abstraction layers like .NET work create and allow developers to do incredible things without having to know a lot. However, when .NET is used in a way unanticipated by its authors which reveals one of its subtle bugs, then that is the time where some win32 API knowledge goes a long way.

Will you ever have a write a message pump? I doubt it. Can it help diagnose problems? You betcha!

Glenn
+2  A: 

Yes, the principles of the Win32 API are useful to learn - these principles are the foundation on which everything else is built.

The .NET APIs for GUI development, both Windows.Forms and WPF, do what they do within the constraints of what is possible on top of the Win32 API. Key architectural decisions of these frameworks were constrained and informed by the Win32 API.

On the other hand, you are less likely to get a lot of value from diving deep into the API, as there is a lot to learn, and given that you spend most of your time working in C#, you'll have less opportunity to use the knowledge directly.

BTW, the same applies to other technologies as well - like networking, cryptography and hardware design. Learning the fundamentals will help you become a better developer.

Bevan
+1  A: 

If I were to start today, I wouldn't learn the entire API. However, I do think that the basic concepts are important to understand, with an understanding of how message loops work as the top priority.

erikkallen
+8  A: 

The question is much like, "Is learning assembly worthwhile"; and the answer is the same:

"Yes, because you will understand the fundamentals, and be able to perceive deeper than those who only work at the top level of abstraction".

However, by the same token, you probably won't be writing Win32 API directly 99.5% of the time.

Paul Nathan
+4  A: 

When they invented C to replace assembly language, people where probably asking: "is it worthwhile to learn assembly language?" The value in knowing both was being able to drop to assembly to do the things which were impossible to accomplish in C (eg. trigger an interrupt).

The same can be said for Win32. There are some things which are impossible to do in C#. If you didn't know the win32 api, then you would dismiss some things as being impossible. However, once you know what you are missing, in those rare situations, you would be able to "drop to win32" and do them.

Another way of looking at it is this: programming is all about being able to think in multiple levels of abstraction at the same time. For example, if you know your language uses immutable strings, you don't write an algorithm that adds a single character to one 10000 times, because it will be slow. If you know the win32 api, you will be able to think about how each line you write in C# is actually implemented and that will help you write better code.

Steve Hanov
A: 

In your career it will be unlikely that you will only be creating greenfield applications where you will have the freedom to choose the technology and programming languages used.

Sooner or later you will have to integrate with old code written in Win32 and C/C++. In that case, knowledge of Win32 will help, especially if you are integrating using PInvoke or C++/CLI.

m-sharp
+3  A: 

Yes, you should learn the basics of how Windows (a lot of this stuff predates Win32) operates. Why? For the same reason as I understand how a mortise and tenon joint operates, even though I don't make my own furniture, or why I understand how an internal combustion engine works even though I don't do my own car maintenance.

You work at a higher level of abstraction, which is nice, but when that abstraction leaks - that's not an "if", that's a "when" - if you don't understand the basics of Windows, you'll be lost. If you don't know at least some of the API, you won't have a clue where to look if you need to P/Invoke functionality not available in .Net.

Quite apart from that, isn't curiousity reason enough?

Bob Moore
+1  A: 

A lot of the "No" answers here seem to focus on learning the actual methods, structs, and what not available in the API. I'd say yes, but focus not on the individual components of the API, but the overall design and the way it functions. It's much easier to troubleshoot even .NET code when you understand what's happening at the core level of the operating system.

Chris
+1  A: 

This question looks a bit dated, but I'll answer anyway.

Answer: Complicated: yes. Simple: probably not necessary.

It really depends on what you need to do. If you need to use a feature not current supported by .NET, have-at-er. But be careful, most of the coddling the Framework provides Win32 does not, and if you do something incredibly stupid, your machine WILL bluescreen.

I know when .NET first came out, I had have no interest to learn Win32, .NET was here and it was such an improvement. But the sad fact about Windows is this: all new features in Windows are implemented in native code first, period. If you want to use any part of Windows before .NET wraps it, you're either using Win32 from C++ or Win32 from C# or from VB.NET. .NET is a wrapper, for all the stuff in Win32. So if you can't wait, yes, you can Interop into the lower bowels of the OS if you'd like.

Knowing Win32 and probably one day Win64 (whatever they happen to call it) will always be a useful skill. Any whizzbang technology requires underpinnings somewhere.

Chris
A: 

Misuse the .NET framework and Win32 and your machine will blue screen? Somehow I doubt that.

The biggest value to knowing Win32 (or assembly language) is that when something doesn't work as expected and you have to debug it. The more you know about the underlying system, the easier time you will have debugging the problem.

James
+1  A: 

.NET is implemented using win32 api, anyone wishing to possess deeper understanding of .NET would greatly benefit from having at least marginal knowlege of win32api.

LoudNPossiblyRight
A: 

I like to further add to this. I never formally studied Win32 API/MFC. I started using Visual C++ 4 when I first got interested in GUI programming. Anyway, I wish I kept that foundation then, as I never caught on quick enough (I was rather young then, actually), so I studied Visual Basic instead.

For some reason, Delphi never interested me even though I knew Pascal well enough, but I digress. These days, I work in IT and develop installer scripts in NSIS - and every so often I need additional functionality that NSIS doesn't provide, so I make my own plugin and to keep it quick and dependency free, I opt for Win32 API opposed to MFC or even full blown C++.

The main reason for this comment, is that my own curiosity got me hooked. I like to know more, so where is the best resource for learning the API. A book? Website?

Would MFC still be worth tackling as well? I did see a website about a fellow that develops Win32 GUI apps, in assembly! I think that is overkill, honestly, but it is compact, fast code, interesting, the concept, but I never was able to get the hang of 80x86 assembly (hell, even RISC assembly in college I never was able to do!)

Jonathan Weinraub
If you're coding for fun,...and assembler is fun to you (God knows why!) then it might be worth writing GUIs this way as a learning exercise but I can't ever imagine telling my boss I was writing something really efficient but it's gonna take me 48 months!
Stimul8d