In all the books, they propagate the managed code and say that it’s practically not necessary to plunge into the unmanaged code.

However, some WinApi analogues do not have in .NET => you have to go into unmanaged code, wrap the library and reinvent the wheel.

It seems that T-shirts have all the sources and should not interfere with them, so that they could transfer all WinApi .NET, but for some reason some of the powerful functions remained in WinApi ...

  • They can promote anything, however, C / C ++ is faster and has access to any giblets. - Vladimir Martyanov
  • 2
    @ Vladimir Martiyanov is not so fast as to compensate for the speed of development, time for debugging and testing, and the cost of good C ++ specialists, and there is something not lying around at every corner. On an assembler, the program will be even faster and more efficient, but for some reason only critical sections are written on it, why would it? - rdorn
  • @ Vladimir Martiyanov and in order not to breed holivar, I don’t give a hint of any advantages, although there is a reason for that, like .net. Just IMHO, goals and objectives should determine the necessary tools, and not vice versa. - rdorn
  • @rdorn And how often do you get to write code better than on it? Yes, the task in question is access to WinAPI. And then sishechka for more than a task. - Vladimir Martyanov
  • @ Vladimir Martiyanov uh ... we don’t consider problems of a higher order? anyway. The difference is not really significant, because and in c you need to write a couple of extra lines to import functions from the DLL. The only bonus si in this case is that some of the work was done for you by providing * .h files to these DLLs. Asma: a more effective solution is almost always the question of the amount of work and necessary knowledge compared to the solution of the same problem in any higher level language, and it was this factor that prompted to create high-level languages ​​at one time. - rdorn

5 answers 5

The fact that in some books purely managed code is being promoted is just a marketing ploy.

The fact is, .NET developers didn’t set a goal to completely replace WinAPI.

The main idea of ​​.NET is to provide a new, simpler and more convenient development platform, while maintaining compatibility with existing platforms - above all, WinAPI and COM.

In certain cases, this may be close enough to reality - for example, you probably won't see P / Invoke in web development. But when developing for a desktop (especially for WinForms) or for a non-web server, you will regularly come across P / Invoke.

Moreover, over time, you will realize how thin the level of abstraction provided by .NET is, and how little managed code is different from unmanaged.

    Generally an interesting question, which rather refers to why the .NET Framework is what it is. And the answer obviously must be sought in the time when it was created. And it was created in an attempt to do "better than Java", and to some extent they succeeded. For example, localization, work with date / time / time zones in .NET was immediately done at the best level (memories of many years ago, probably now the situation has already changed). At the time of .NET 1.0 / 1.1, the set of classes / methods generally looked rather pale compared to WinAPI, since then it has become much more complete.

    From the very first versions of dotnet, there was Interop and P / Invoke, which actually allows you to call WinAPI, and what is really wrong with that? I would not say that this is the invention of the bicycle - you just call the external function in the unmanaged code, the only thing is to do it right, that's all.

    Next, you should probably speak in detail - what exactly is lacking, what functions.

    Let me remind you about the list: Microsoft Win32 to Microsoft .NET Framework API Map https://msdn.microsoft.com/en-us/library/aa302340.aspx

      Initially, .NET was really created as an alternative to Java after another showdown with Sun Microsystems, because the improvements and changes made by Microsoft to the Java virtual machine for Windows led to incompatibility of Java code on different platforms, which is contrary to the Java ideology.

      Because .NET for a long time did not even try to make it cross-platform, and even now it is very conditional, then over time, for the most common Win API calls, at that time the only Win32, ready-made shells were included in .NET. Rarely used functions can always be connected by hand when needed.

      Without going into details and differences, .NET, like Java, is a virtual machine. This allows on the one hand to forget about the hardware differences of the platforms, on the other it imposes a number of significant restrictions, in particular, on direct access to the hardware. A significant part of the API is a library of functions for conveniently using low-level calls to drivers, devices, and functions of the OS kernel, which, in one way or another, depend on the hardware platform. For example, DirectX, to which, by the way, is still not a native shell in .NET, WPF does not count, there you can not control the rendering process.

        What WinAPI, .NET should have been self-sufficient and cross-platform.

        • For what a minus ??? - cpp_user

        Everything is there. Just hidden.

        .Net is a higher level language than cpp.

        And winAPI is a windows aplication program interface, in simple terms, the rule of windows interaction in windows. You can not get around them, based on this Windows.

        • Well, I do not know ... I was able to find an analogue of CopyFileEx in Net. Or use Win Api or drank the bike ... - iluxa1810
        • msdn.microsoft.com/ru-ru/library/ms127964(v=vs.110).aspx think how it works? causes the same winAPI - hitcode
        • I am a little mistaken ... Here is an analog of this function, I did not find MoveFileEx. There is a flag that allows you to manipulate files at the time of the reboot. - iluxa1810