Does it make sense to study low-level WinAPI software?

Does it make sense, with all of C # -controlled bliss, to return to Windows Petzold programming and try to create code with pure WinAPI?

What can you learn from it? Isn't it too outdated to be useful?

+49
windows winapi
Aug 08 '08 at 0:29
source share
22 answers

This question borders on religious :) But I will give my thoughts anyway.

I see value when using the Win32 API. Most, if not all, GUI libraries (managed or unmanaged) lead to Win32 API calls. Even the most complete libraries do not cover 100% of the API, and therefore there are always spaces that need to be connected by direct API calls or P / invoking. Some wrapper names around API calls have similar names for API calls, but these names are not entirely self-documenting. Therefore, understanding the core API and the terminology used in it will help you understand the interface APIs and what they actually do.

Also, if you understand the nature of the basic APIs that are used in the frameworks, then you will make the best choice as to which library functionality you should use in this scenario.

Hurrah!

+58
Aug 08 '08 at 1:00
source share

I spent a long time doing standard C / C ++ before learning the Win32 API, and to be pretty dumb, the “Win32 API training” part is not the best technical experience in my life.

In one hand, the Win32 API is pretty cool. This is similar to the extension of the standard C API (which requires fopen when you can have CreateFile ). But I think UNIX / Linux / WhateverOS have the same gizmo functions. In any case, on Unix / Linux they have a “Everything is file”. On Windows, they have "Everything is ... Window" (don't joke! See CreateWindow !).

On the other hand, it is an outdated API. You will deal with raw C and raw C madness.

  • How to tell one structure its own size in order to pass a void * pointer to some Win32 function.
  • Messaging can be quite confusing: mixing C ++ objects with Win32 windows leads to very interesting examples of a chicken or egg problem (funny moments when you write delete this ; in the class method).
  • Having a WinProc subclass when you are more familiar with object inheritance is a split voice and less optimal.
  • And, of course, there is the joy of “ Why did they do fracking this way in this world? ” Moments when you hit your keyboard with your head, when too much, and return home with keys engraved on your forehead, just because someone thought it’s logical to write an API to enable the color change of the “window”, not by changing one of its properties, but referring to its parent window.
  • and etc.

In the last hand ( three hands ??? ), think that some people working with outdated APIs themselves use outdated code style. The moment you hear “ const for mannequins ” or “ I don’t use namespaces because they decrease the execution speed ” or even better “ Hey, who needs C ++? Am I code in my own brand of object-oriented C !!! "(I’m not joking ... In a professional environment, and the result was quite spectacular ...) I feel that only the condemned one feels fear only before guillotine .

So ... All in all, this is an interesting experience.

Edit

After reading this post again, I see that it can be considered too negative. This is not true.

Sometimes it’s interesting (as well as frustrating) to know how everything works under the hood. You will realize that despite the huge (impossible?) Limitations, the Win32 API team did a wonderful job to make sure that everything from you olde Win16 program to your last Win64 over-top application can work together, in past, now and in the future.

Question: Do you really want to?

Since spending weeks to do what can be done (and done better) in other higher-level and / or object-oriented APIs can be quite de-motivational (real life experience: 3 weeks for the Win API, versus 4 hours for three other languages ​​and / or libraries).

In any case, you will find that the Raymond Chen blog is very interesting because of its internal view of the Win API and its evolution over the years:

https://blogs.msdn.microsoft.com/oldnewthing/

+20
Sep 19 '08 at 18:37
source share

Native APIs are the “real” operating system APIs. The .NET library (with a few exceptions) is nothing more than a fancy wrapper around them. So yes, I would say that anyone who can understand .NET with all its complexity can understand relatively mundane things, such as talking to an API without the benefit of the average person.

Just try a DLL injection from managed code. It's impossible. You will have to write your own code for this, to configure the window, for a real subclass, and a dozen other things.

So yes: you must know both.

Edit: even if you plan to use P / Invoke.

+15
Aug 08 '08 at 0:53
source share

That's right. When no one knows the low level, who will update and write high level languages? In addition, when you understand low-level material, you can write more efficient code in a higher-level language, and debug more efficiently.

+14
Aug 08 '08 at 0:31
source share

Assuming you are building Windows-oriented applications:

  • it may be informative to understand the lower levels of the system - how they work, how your code interacts with them (even if it is indirect), and where you have additional parameters that are not available in higher level abstractions
  • There are times when your code may not be as efficient, high-performance, or accurate enough for your requirements.
  • However, in any case, people like us (who have never recognized “unmanaged coding”) will be able to remove the programming that we are trying to do without Win32 “learning”.
  • In addition, there are many sites that provide working samples, code snippets, and even fully functional source code that you can “use” (borrow, plagiarize), but make sure you comply with the reuse license or copyright!) To fill in any spaces that are not handled by the .NET Framework class libraries (or libraries that you can download or receive).
  • If you manage to cope with these skills without messing up in Win32, and you are good at developing well-formed, readable managed code, then I would say that mastering .NET would be a better choice than expanding yourself in two different environments.
  • If you often need to use those Windows features that haven't gotten a good coverage of the Framework class library, then by all means, learn the necessary skills.
  • I personally spent too much time worrying about the “other areas” of coding, which I must understand in order to create “good programs,” but there are many masochists who think everyone needs and desires are like them. Suffering loves company. :)

Assuming you are building applications for the Web 2.0 world, or it would be just as useful and useful for NIX and MacOS users:

  • Stick to languages ​​and compilers that target as many cross-platform environments as possible.
  • pure .NET in Visual Studio is better than Win32, but development using the MONO libraries, possibly using the Sharp Develop IDE, is probably an even better approach.
  • you can also spend your time learning Java, and these skills are very well transferred to programming in C # (plus Java code will theoretically work on any platform with the corresponding JRE). I heard that he said that Java is more like "write once, debug everywhere", but this is probably as true as (or even more than) C #.
+11
Aug 09 '08 at 20:27
source share

Analogy: If you build cars for life (programming), then it is very important to know how the engine works (Win32).

+9
Aug 08 '08 at 1:01
source share

The simple answer, YES.

+8
Aug 08 '08 at 1:16
source share

This is the answer to any question that is similar to ... "does it make sense to study the low-level language / api X, even when in the higher-level language / api Y there is

Yes

You can download your Windows PC (or any other OS) and ask this question in SO, because a couple of guys from Microsoft wrote 16-bit assembler code that loads your OS.

Your browser works because someone wrote the core of the OS in C, which serves all your requests in the browser.

This is fully consistent with scripting languages.

Big or small, there is always a market and the ability to write something at any level of abstraction. You just need to like it and fit into the right job.

No api / language at any level of abstraction does not matter if there is no better competitor at the same level .

Another way to look at this: a good example from one of Michael Abrash’s books: C was asked to write a function to clear the screen. Because C was a better (higher) build abstraction and everything, a programmer knew only C and knew well. He did everything possible - he moved the cursor to every place on the screen and cleared the character there. He optimized the cycle and made sure that it works as fast as he can. But still it was slow ... until some guy appeared and said that there was some kind of BIOS / VGA instruction or something that could immediately clear the screen.

It always helps to know that you are walking.

+7
May 29 '10 at 3:17
source share

Yes, for several reasons:

1) .net wraps Win32 code ..net is usually an excellent system for coding, but with some knowledge of the Win32 base layer (oops, WinAPI now that there is 64-bit code) it helps you find out what is actually business is happening.

2) in this economy, it is better to have some advantages over the other guy when you are looking for work. Some WinAPI features may provide this to you.

3) some system aspects are not yet available through the .net infrastructure, and if you want to access these functions, you will need to use p / invoke (see http://www.pinvoke.net for some help there). Having at least a little WinAPI experience will make your p / invoke efforts more efficient.

4) (added) Now that Win8 has been around for some time, it is still built on top of WinAPI. iOS, Android, OS / X and Linux are all there, but WinAPI will still be there for many years.

+6
Jul 17 '09 at 6:17
source share

Learning a new language or programming technology for one of three reasons:
1. Needed: you are starting a project to create a web application, and you do not know anything about ASP.NET
2. Enthusiasm: you are very excited about ASP.NET MVC. why not try it?
3. Free time: but who doesn’t care.

The best reason to learn something new is Need. If you need to do something that the .NET framework cannot do (for example, performance), then WinAPI is your solution. Until then, we continue to read .NET.

+4
Aug 08 '08 at 1:56
source share

For most desktop needs, you do not need to know Win32, however Win32 LOT is not in .NET, but it is at a cost that may be less than 1% of your application.

USB support, HID support, Windows Media Foundation on my head. There are many interesting Vista APIs available only from Win32.

You will do yourself a great service by learning to interact with the Win32 API if you program on the desktop, because when you need to call Win32 and you do, you won’t spend a week scratching your head.

+4
Aug 08 '08 at 16:53
source share

Personally, I don’t really like the Win32 API, but it makes sense to study it, since the API will allow more control and efficient use of the GUI than a language such as Visual Basic, and I believe that if you are going to do you should know the API, even if you don’t use it directly. This is for reasons similar to the ones that C is useful to learn, for example, how strcpy takes longer than copying an integer, or why you should use pointers to arrays as function parameters instead of arrays by value.

+4
Aug 21 '08 at 13:07
source share

Learning C or a lower level language can definitely be useful. However, I see no obvious benefit when using unmanaged WinAPI.

+3
Aug 08 '08 at 0:35
source share

I saw the low-level Windows API code ... it is not very ... I'm sorry that I can not wean it. I think this is useful for learning low-level, like in C, since you better understand the hardware architecture and how it all works. Learning the old Windows API ... I think that the material may be left for people at Microsoft who may need to learn it to create higher-level languages ​​and APIs ... they built it, let them suffer along with it; -)

However, if you happen to find a situation where you feel that you simply cannot do what you need to do in a higher level language (a little and far away), then perhaps start a dangerous immersion in this world.

+3
Aug 08 '08 at 0:40
source share

Yes. take a look at uTorrent, the amazing piece of software performance. Half of its small size is explained by the fact that most of its main components have been rewritten so as not to use the gargatuian libraries.

Most of this cannot be accomplished without understanding how these libraries interact with the lower-level API.

+3
Jun 11 '09 at 3:53
source share

It is important to know what is available in the Windows API. I don’t think you need to scroll through the code, but you need to know how it works..NET Framework contains a lot of functionality, but does not contain managed code equivalents for the entire Windows API. Sometimes you need to get a little closer to metal, and knowing what is there and how it behaves, you can better understand how to use it.

+2
Aug 08 '08 at 2:21
source share

This is really the same as asking if I should learn a low-level language such as C (or even assembler).

Coding in it, of course, is slower (although, of course, the result is much faster), but its true advantage is that you get an idea of ​​what is happening at the system level, and not just understand another metaphor for what is going on.

It may also be better when things are not so good, or fast enough, or with the degree of detail that you need. (And at least some subclasses and superclasses.)

+2
Sep 12 '08 at 6:20
source share

I will say that. I don't like Win32 API programming. This can be a pain compared to managed code. BUT, I am glad that I know this because I can write programs that otherwise I would not be able to. I can write programs that other people cannot. Plus it gives you more information on what your managed code is doing behind the scenes.

+2
Sep 26 '08 at 2:01
source share

The amount of value that you get from learning the Win32 API (excluding the general information that you learn from how the nuts and bolts of the machine fit together) depends on what you are trying to achieve. Many Win32 APIs are well complemented by .NET library classes, but not all. If, for example, you want to make serious audio programming, this part of the Win32 API will be an excellent subject to study, because only the most basic operations are available from the .NET classes. The last thing I checked, even the DirectX DirectSound managed library was awful.




At the risk of shameless self-promotion ....

I just came across a situation where the Win32 API was my only option. I want to have different hints for each item in the list. I wrote how I did this on this question .

+2
Sep 26 '08 at 3:01
source share

Even in very high-level languages, you still use the API. What for? Well, not every aspect of the API has been replicated by various libraries, frames, etc. You need to learn the API until you need an API to accomplish what you are trying to do. (And no more.)

+2
Jun 28 '09 at 18:49
source share

Besides some special cases when you need direct access to the API, I would say NO.

It takes considerable time and effort to learn how to properly implement your own API calls, and the return value is simply not worth it. I would rather spend time exploring new hot technologies or frameworks that will make your life easier and make programming less painful. Not perennial legacy COM libraries that no one else uses (sorry COM users).

Please do not rock me for this point of view. I know that many engineers have really curious souls, and there is nothing wrong with learning how everything works. Curiosity is good and really helps to understand. But from a managerial point of view, I would rather spend a week studying Android application development than call OLE or COM.

+2
Apr 23 2018-12-12T00:
source share

If you plan to develop a cross-platform application, if you use win32, then your application can easily be launched via linux via WINE. This results in high service. This is one of the benefits of learning win32.

+1
Jun 28 '09 at 18:59
source share



All Articles