<p>Does it make sense, having all of the C#-managed-bliss, to go back to Petzold's Programming Windows and try to produce code w/ pure WinAPI?</p>

<p>What can be learn from it? Isn't it just too outdated to be useful?</p>

[{'answer_id': 5508, 'author': 'Ed.', 'author_id': 522, 'author_profile': 'https://Stackoverflow.com/users/522', 'pm_score': 4, 'selected': False, 'text': '<p>Absolutely.  When nobody knows the low level, who will update and write the high level languages?  Also, when you understand the low level stuff, you can write more efficient code in a higher level language, and also debug more efficiently.</p>\n'}, {'answer_id': 5510, 'author': 'Greg', 'author_id': 108, 'author_profile': 'https://Stackoverflow.com/users/108', 'pm_score': 2, 'selected': False, 'text': "<p>Learning C or a lower level language can definitely be useful. However, I don't see any obvious advantage in using the unmanaged WinAPI.</p>\n"}, {'answer_id': 5513, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 2, 'selected': False, 'text': "<p>I've seen low level Windows API code... it ain't pretty... I wish I could unlearn it.  I think it benefits to learn low level as in C, as you gain a better understanding of the hardware architecture and how all that stuff works.  Learning old Windows API... I think that stuff can be left to the people at Microsoft who may need to learn it to build higher level languages and API... they built it, let them suffer with it ;-)</p>\n\n<p>However, if you happen to find a situation where you feel you just can't do what you need to do in a higher level language (few and far between), then perhaps start the dangerous dive into that world.</p>\n"}, {'answer_id': 5521, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>The native APIs are the "real" operating system APIs. The .NET library is (with few exceptions) nothing more than a fancy wrapper around them. So yes, I\'d say that anybody who can understand .NET with all its complexity, can understand relatively mundane things like talking to the API without the benefit of a middle-man.</p>\n\n<p>Just try to do DLL Injection from managed code. It can\'t be done. You will be forced to write native code for this, for windowing tweaks, for real subclassing, and a dozen other things.</p>\n\n<p>So yes: you should (must) know both.</p>\n\n<p>Edit: even if you plan to use P/Invoke.</p>\n'}, {'answer_id': 5524, 'author': 'OJ.', 'author_id': 611, 'author_profile': 'https://Stackoverflow.com/users/611', 'pm_score': 7, 'selected': True, 'text': "<p>This question is bordering on religious :) But I'll give my thoughts anyway.</p>\n\n<p>I do see value in learing the Win32 API. Most, if not all, GUI libraries (managed or unmanaged) result in calls to the Win32 API. Even the most thorough libraries don't cover 100% of the API, and hence there are always gaps which need to be plugged by direct API calls or P/invoking. Some of the names of the wrappers around the API calls have similar names to the underlying API calls, but those names aren't exactly self-documenting. So understanding the underlying API, and the terminology used therein, will aid in understanding the wrapper APIs and what they actually do.</p>\n\n<p>Plus, if you understand the nature of the underlying APIs that are used by frameworks, then you will make better choices with regards to which library functionality you should use in a given scenario.</p>\n\n<p>Cheers!</p>\n"}, {'answer_id': 5525, 'author': 'Joel Lucsy', 'author_id': 645, 'author_profile': 'https://Stackoverflow.com/users/645', 'pm_score': 3, 'selected': False, 'text': '<p>Analogy: If you build cars for a living (programming), then its very pertinent to know how the engine works (Win32).</p>\n'}, {'answer_id': 5535, 'author': 'Stephen Cox', 'author_id': 534, 'author_profile': 'https://Stackoverflow.com/users/534', 'pm_score': 3, 'selected': False, 'text': '<p>Simple answer, YES.</p>\n'}, {'answer_id': 5573, 'author': 'Amr', 'author_id': 463, 'author_profile': 'https://Stackoverflow.com/users/463', 'pm_score': 2, 'selected': False, 'text': "<p>Learning a new programming language or technology is for one of three reasons:<br/>\n1. Need: you're starting a project for building a web application and you don't know anything about ASP.NET<br/>\n2. Enthusiasm: you're very excited about ASP.NET MVC. why not try that?<br/>\n3. Free time: but who has that anyway.</p>\n\n<p>The best reason to learn something new is Need. If you need to do something that the .NET framework can't do (like performance for example) then WinAPI is your solution. Until then we keep ourself busy with learning about .NET</p>\n"}, {'answer_id': 5587, 'author': 'Chris Miller', 'author_id': 206, 'author_profile': 'https://Stackoverflow.com/users/206', 'pm_score': 2, 'selected': False, 'text': "<p>It's important to know what is available with the Windows API.  I don't think you need to crank out code with it, but you should know how it works.  The .NET Framework contains a lot of functionality, but it doesn't provide managed code equivalents for the entire Windows API.  Sometimes you have to get a bit closer to the metal, and knowing what's down there and how it behaves will give you  a better understanding of how to use it.</p>\n"}, {'answer_id': 6139, 'author': 'Brian Leahy', 'author_id': 580, 'author_profile': 'https://Stackoverflow.com/users/580', 'pm_score': 2, 'selected': False, 'text': "<p>For most needs on the desktop you wont need to know the Win32, however there is a LOT of Win32 not in .NET, but it is in the outlaying stuff that may end up being less than 1% of your application.</p>\n\n<p>USB support, HID support, Windows Media Foundation just off the top of my head. There are many cool Vista API's only available from Win32.</p>\n\n<p>You will do yourself a large favor by learning how to do interop with a Win32 API, if you do desktop programing, because when you do need to call Win32, and you will, you won't spend weeks scratching your head.</p>\n"}, {'answer_id': 6906, 'author': 'ParanoidMike', 'author_id': 452120, 'author_profile': 'https://Stackoverflow.com/users/452120', 'pm_score': 4, 'selected': False, 'text': '<p>On the assumption that you\'re building apps targeted at Windows:</p>\n\n<ul>\n<li>it can sure be informative to understand lower levels of the system - how they work, how your code interacts with them (even if only indirectly), and where you have additional options that aren\'t available in the higher-level abstractions</li>\n<li>there are times when your code might not be as efficient, high-performance or precise enough for your requirements</li>\n<li>However, in more and more cases, folks like us (who never learned "unmanaged coding") will be able to pull off the programming we\'re trying to do without "learning" Win32.</li>\n<li>Further, there\'s plenty of sites that provide working samples, code fragments and even fully-functional source code that you can "leverage" (borrow, plagiarize - but check that you\'re complying with any re-use license or copyright!) to fill in any gaps that aren\'t handled by the .NET framework class libraries (or the libraries that you can download or license).</li>\n<li>If you can pull off the feats you need without messing around in Win32, and you\'re doing a good job of developing well-formed, readable managed code, then I\'d say mastering .NET would be a better choice than spreading yourself thin over two very different environments.</li>\n<li>If you frequently need to leverage those features of Windows that haven\'t received good Framework class library coverage, then by all means, learn the skills you need.</li>\n<li>I\'ve personally spent far too much time worrying about the "other areas" of coding that I\'m <em>supposed</em> to understand to produce "good programs", but there\'s plenty of masochists out there that think everyone\'s needs and desires are like their own.  Misery loves company.  :)</li>\n</ul>\n\n<p>On the assumption that you\'re building apps for the "Web 2.0" world, or that would be just as useful/beneficial to *NIX &amp; MacOS users:</p>\n\n<ul>\n<li>Stick with languages and compilers that target as many cross-platform environments as possible.</li>\n<li>pure .NET in Visual Studio is better than Win32 obviously, but developing against the MONO libraries, perhaps using the Sharp Develop IDE, is probably an even better approach.</li>\n<li>you could also spend your time learning Java, and those skills would transfer very well to C# programming (plus the Java code would theoretically run on any platform with the matching JRE).  I\'ve heard it said that Java is more like "write once, debug everywhere", but that\'s probably as true as (or even moreso than) C#.</li>\n</ul>\n'}, {'answer_id': 19814, 'author': 'Jeff Linahan', 'author_id': 2222, 'author_profile': 'https://Stackoverflow.com/users/2222', 'pm_score': 2, 'selected': False, 'text': "<p>Personally I don't really like the Win32 API but there's value in learning it as the API will allow more control and efficiency using the GUI than a language like Visual Basic, and I believe that if you're going to make a living writing software you should know the API even if you don't use it directly.  This is for reasons similar to the reasons it's good to learn C, like how a strcpy takes more time than copying an integer, or why you should use pointers to arrays as function parameters instead of arrays by value.</p>\n"}, {'answer_id': 58404, 'author': 'David L Morris', 'author_id': 3137, 'author_profile': 'https://Stackoverflow.com/users/3137', 'pm_score': 2, 'selected': False, 'text': "<p>This is really the same as the question, should I learn a low level language like C (or even assembler).</p>\n\n<p>Coding in it is certainly slower (though of course the result is much faster), but its true advantage is you gain an insight into what is happening at close to the system level, rather than than just understanding someone else's metaphor for what is going on.</p>\n\n<p>It can also be better when things won't work well, or fast enough or with the sort of granularity that you need.  (And do at least some subclassing and superclassing.)</p>\n"}, {'answer_id': 104394, 'author': 'paercebal', 'author_id': 14089, 'author_profile': 'https://Stackoverflow.com/users/14089', 'pm_score': 5, 'selected': False, 'text': '<p>I kept to standard C/C++ for years before learning Win32 API, and to be quite blunt, the &quot;learning Win32 API&quot; part is not the best technical experience of my life.</p>\n<p>In one hand Win32 API is quite cool. It\'s like an extension of the C standard API (who needs <code>fopen</code> when you can have <code>CreateFile</code>. But I guess UNIX/Linux/WhateverOS have the same gizmo functions. Anyway, in Unix/Linux, they have the &quot;Everything is a file&quot;. In Windows, they have the &quot;Everything is a... Window&quot; (no kidding! See <code>CreateWindow</code>!).</p>\n<p>In the other hand, this is a legacy API. You will be dealing with raw C, and raw C madness.</p>\n<ul>\n<li>Like telling one\'s structure its own size to pass through a <code>void *</code> pointer to some Win32 function.</li>\n<li>Messaging can be quite confusing, too: Mixing C++ objects with Win32 windows lead to very interesting examples of <a href="http://en.wikipedia.org/wiki/The_chicken_or_the_egg" rel="noreferrer">Chicken or Egg</a> problem (funny moments when you write a kind of <code>delete this ;</code> in a class method).</li>\n<li>Having to subclass a WinProc when you\'re more familiar with object inheritance is head-splitting and less than optimal.</li>\n<li>And of course, there is the joy of &quot;<i>Why in this fracking world they did this thing this way ??</i>&quot; moments when you strike your keyboard with your head once too many and get back home with keys engraved in your forehead, just because someone thought it more logical to write an API to enable the changing of the color of a &quot;Window&quot;, not by changing one of its properties, but by asking it to its parent window.</li>\n<li>etc.</li>\n</ul>\n<p>In the last hand (<i>three hands ???</i>), consider that some people working with legacy APIs are themselves using legacy code styling. The moment you hear &quot;<i><code>const</code> is for dummies</i>&quot; or &quot;<i>I don\'t use namespaces because they decrease the runtime speed</i>&quot;, or the even better &quot;<i>Hey, who needs C++? I code in my own brand of object-oriented C!!!</i>&quot; (No kidding... In a professional environment, and the result was quite a sight...), you\'ll feel the kind of dread only condemned feel in front of the <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Guillotine" rel="noreferrer">guillotine</a>.</p>\n<p>So... All in all, it\'s an <em>interesting</em> experience.</p>\n<h2>Edit</h2>\n<p>After re-reading this post, I see it could be seen as overly negative. It is not.</p>\n<p>It is sometimes interesting (as well as frustrating) to know how the things work under the hood. You\'ll understand that, despite enormous (impossible?) constraints, the Win32 API team did wonderful work to be sure everything, from you &quot;olde Win16 program&quot; to your &quot;last Win64 over-the-top application&quot;, can work together, in the past, now, and in the future.</p>\n<p>The question is: Do you really want to?</p>\n<p>Because spending weeks to do things that could be done (and done better) in other more high-level and/or object-oriented API can be quite de-motivational (real life experience: 3 weeks for Win API, against 4 hours in three other languages and/or libraries).</p>\n<p>Anyway, you\'ll find Raymond Chen\'s Blog very interesting because of his insider\'s view on both Win API and its evolution through the years:</p>\n<p><a href="https://blogs.msdn.microsoft.com/oldnewthing/" rel="noreferrer">https://blogs.msdn.microsoft.com/oldnewthing/</a></p>\n'}, {'answer_id': 137345, 'author': 'Slapout', 'author_id': 19072, 'author_profile': 'https://Stackoverflow.com/users/19072', 'pm_score': 2, 'selected': False, 'text': "<p>I'll put it this way. I don't like programming to the Win32 API. It can be a pain compared to managed code. BUT, I'm glad I know it because I can write programs that otherwise I wouldn't be able to. I can write programs that other people can't. Plus it gives you more insight into what your managed code is doing behind the scenes. </p>\n"}, {'answer_id': 137515, 'author': 'Michael Lang', 'author_id': 19452, 'author_profile': 'https://Stackoverflow.com/users/19452', 'pm_score': 2, 'selected': False, 'text': '<p>The amount of value you get out of learning the Win32 API, (aside from the sorts of general insights you get from learning about how the nuts and bolts of the machine fit together) depends on what you\'re trying to achieve.  A lot of the Win32 API has been wrapped nicely in .NET library classes, but not all of it.  If for instance you\'re looking to do some serious audio programming, that portion of the Win32 API would be an excellent subject of study because only the most basic of operations are available from .NET classes.  Last I checked even the managed DirectX DirectSound library was awful. </p>\n\n<hr>\n\n<p>At the risk of shameless self-promotion....</p>\n\n<p>I just came across a situation where the Win32 API was my only option.  I want to have different tooltips on each item in a listbox.  I wrote up how I did it on <a href="https://stackoverflow.com/questions/192584/how-can-i-set-a-different-tooltip-text-for-each-item-in-a-listbox">this question</a>. </p>\n'}, {'answer_id': 979245, 'author': 'Ape-inago', 'author_id': 42082, 'author_profile': 'https://Stackoverflow.com/users/42082', 'pm_score': 2, 'selected': False, 'text': "<p>yes.  take a look at uTorrent, an amazing piece of software efficiency.  Half of it's small size is due to the fact that much of it's core components were re-written to not use gargatuian libraries.  </p>\n\n<p>Much of this couldn't be done without understanding how these libraries interface with the lower level API's</p>\n"}, {'answer_id': 1055503, 'author': 'Oorang', 'author_id': 102270, 'author_profile': 'https://Stackoverflow.com/users/102270', 'pm_score': 2, 'selected': False, 'text': '<p>Even in very very high level languages you still make use of the API. Why? Well not every aspect of the API has been replicated by the various libraries, frameworks, etc. You need to learn the API for as long as you will need the API to accomplish what you are trying to do. (And no longer.)</p>\n'}, {'answer_id': 1055522, 'author': 'Manohar', 'author_id': 57937, 'author_profile': 'https://Stackoverflow.com/users/57937', 'pm_score': 1, 'selected': False, 'text': '<p>If you planning to develop a cross platform application, If you use win32, then your application could easily run on linux through WINE. This results in a highly maintainable application. This is one of the advantages of learning win32.</p>\n'}, {'answer_id': 1141647, 'author': 'Jay', 'author_id': 118962, 'author_profile': 'https://Stackoverflow.com/users/118962', 'pm_score': 3, 'selected': False, 'text': '<p>Yes, for a few reasons:</p>\n\n<p>1)  .net wraps Win32 code.  .net is usually a superior system to code against, but having some knowledge of the underlying Win32 layer (oops, WinAPI now that there is 64-bit code too) bolsters your knowledge of what is really happening.</p>\n\n<p>2)  in this economy, it is better to have some advantages over the other guy when you are looking for a job.  Some WinAPI experience may provide this for you.</p>\n\n<p>3)  some system aspects are not available through the .net framework yet, and if you want to access those features you will need to use p/invoke (see <a href="http://www.pinvoke.net" rel="nofollow noreferrer">http://www.pinvoke.net</a> for some help there).  Having at least a smattering of WinAPI experience will make your p/invoke development effort a lot more efficient.</p>\n\n<p>4)  (added)  Now that Win8 has been around for awhile, it is <em>still</em> built on top of the WinAPI.  iOS, Android, OS/X, and Linux are all out there, but the WinAPI will still be out there for many many years.</p>\n'}, {'answer_id': 2933628, 'author': 'Senthil', 'author_id': 348342, 'author_profile': 'https://Stackoverflow.com/users/348342', 'pm_score': 3, 'selected': False, 'text': '<p>This is the answer to any question that is like.. <em>"does it make sense to learn a low level language/api X even when a higher level language/api Y is there"</em></p>\n\n<p><strong>YES</strong></p>\n\n<p>You are able to boot up your Windows PC (or any other OS) and ask this question in SO because a couple of guys in Microsoft wrote 16-bit assembly code that loads your OS.</p>\n\n<p>Your browser works because someone wrote an OS kernel in C that serves all your browser\'s requests.</p>\n\n<p>It goes all the way up to scripting languages.</p>\n\n<p>Big or small, there is always a market and opportunity to write something in any level of abstraction. You just have to like it and fit in the right job.</p>\n\n<p>No api/language at any level of abstraction is irrelevent <strong>unless there is a better one competing at the same level</strong>.</p>\n\n<p>Another way of looking at it: A good example from one of Michael Abrash\'s book: A C programmer was given the task of writing a function to clear the screen. Since C was a better (higher level) abstraction over assembly and all, the programmer only knew C and knew it well. He did his best - he moved the cursor to each location on the screen and cleared the character there. He optimized the loop and made sure it ran as fast as it could. But still it was slow... until some guy came in and said there was some BIOS/VGA instruction or something that could clear the screen instantly.</p>\n\n<p>It always helps to know what you are walking on.</p>\n'}, {'answer_id': 10284630, 'author': 'Jakub Zaverka', 'author_id': 1043352, 'author_profile': 'https://Stackoverflow.com/users/1043352', 'pm_score': 2, 'selected': False, 'text': "<p>Apart from some very special cases when you need direct access to APIs, I would say NO. </p>\n\n<p>There is considerable time and effort required to learn to implement the native API calls correctly and the returning value is just not worth it. I would rather spend the time learning some new hot technology or framework that will make your life easier and programming less painful. Not decades-old obsolete COM libraries that nobody really uses anymore (sorry to COM users).</p>\n\n<p>Please don't stone me for this view. I know a lot of engineers here have really curious souls and there is nothing wrong with learning how things work. Curiousity is good and really helps understanding. But from a managerial point of view, I would rather spend a week learning how to develop Android apps than how to calls OLEs or COMs.</p>\n"}]
['https://Stackoverflow.com/questions/5507', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/861/']