WinFX: An All-Managed API
by Ian Griffiths, co-author of Mastering Visual Studio .NET11/24/2003
In Longhorn, Win32 will no longer be the principal API. It will, of course, continue to be supported; 20-year-old DOS applications still run on the latest version of Windows, and likewise, Win32 applications will also continue to work for the foreseeable future. But just as DOS and 16-bit Windows applications were superseded by Win32 applications, so in Longhorn will Win32 become the "old way" of doing things. In Win32's place is a new API called WinFX (pronounced "Win Effects"). WinFX is a significant milestone in the history of the Windows API, as it puts .NET at the center of the platform. While Win32, the main API for previous versions of Windows, is a C-style API, WinFX is designed primarily to be used by .NET languages. In other words, it is a managed API. Moreover, it is a superset of the existing .NET Framework.
Judging by the discussions on various newsgroups and mailing lists, many seasoned Windows developers seem to have a hard time believing that Longhorn's new APIs really will be pure .NET. The topic has come up almost every day on the various WinFX Microsoft newsgroups since the API's announcement, and it seems that many people think that a .NET-only API cannot possibly exist, and that there must be a 'real' Win32 API underneath it all.
|
Related Reading
.NET Framework Essentials |
The idea that Win32 must be lurking somewhere beneath the covers presumably originates in part because of the way today's .NET Framework is implemented. Many of the classes in the Framework Class Library are wrappers on top of Win32 functionality. For example, Windows Forms puts a .NET face on classic Win32 features such as HWND, MSG, and WndProc. Likewise, the various classes in System.Net and System.Net.Sockets ultimately wrap the services provided by the Windows Sockets API in Win32.
However, there's no technical requirement for new WinFX functionality to wrap a corresponding Win32 API. Indeed, we can look to existing Windows and .NET technology to see why this need not be the case.
Platform Layers
It is tempting for experienced Windows developers to think of Win32 as the fundamental API of Windows. All of the unmanaged language runtimes shipped by Microsoft to date rely on Win32, even though they may hide it behind some language-specific wrapper such as the standard C library, or the unique world view that is Visual Basic 6. Similarly, the .NET Frameworks that have shipped so far all rely on Win32 as well. However, Win32 is not an island.
Win32 itself relies on underlying services from the Windows kernel. If you look inside some of the DLLs that implement the Win32 API (such as User32.dll) you will find that many of the functions have very short implementations; they use the Pentium's INT instruction to make a system call that does the real work.
One of the reasons for this is that Windows NT was originally designed to support multiple 'subsystems'. Win32 was just one of these. The first versions of NT also shipped with an OS/2 subsystem and a POSIX subsystem, each of which presented a completely different API, but all of which ran on top of the same set of system services. Of course, OS/2 and POSIX are no longer especially relevant in Windows, making the subsystem support seems like a historical footnote. However, there are still good reasons for certain Win32 APIs to be implemented as little more than a system call, even if subsystems had never been invented, as there are some system services that can only be implemented in the kernel itself.
It has always been possible to bypass Win32 and use the Windows kernel services directly. However, developers rarely do this because such code is unlikely to be portable from one version of Windows to the next. Not only is this low-level API not documented, it can also differ from platform to platform. The kernel in the Windows NT, 2000, and XP product line is very different from the underlying kernel in Windows 95, 98, and ME. Each version of Windows has its own implementation of the Win32 DLLs (GDI32.dll, User32.dll, and so on) to bridge the gap between the common public Win32 API and the platform-specific, low-level system API.
For applications that need to run on more than one version of Windows (that is, most Windows applications) it makes no sense to try and use the low-level system calls. However, WinFX will be installed as part of the operating system just like Win32 is today. This means that unlike the current redistributable versions of the .NET Framework, any particular version of WinFX will not need to be able to work on multiple versions of Windows. The relationship between WinFX and the OS kernel can become much more like the relationship between, say, User32.dll and the OS kernel. (Nobody expects to be able to copy the Windows 98 version of User32.dll onto their Windows XP machine and have it work. The same will be true of the files that make up WinFX.)
Because WinFX will be a part of the OS, it will be able to have a much closer relationship with the low-level system services. In theory, WinFX could act as a peer of Win32 rather than having to be its client; it could effectively be a distinct subsystem. In practice, that's unlikely to happen any time soon for two reasons. First, where Win32 already provides the necessary services, there seems little point in WinFX reinventing the wheel. So expect those parts of the .NET Framework that are wrappers around Win32 (such as Windows Forms) to remain so for the foreseeable future. The second reason for not making WinFX an entirely independent subsystem is that P/Invoke would be tricky to implement if Win32 wasn't still there somewhere.
Nevertheless, although we are likely to carry on seeing wrappers where Win32 already provides appropriate services, there's no reason for new services to be exposed at the Win32 level and then wrapped by WinFX. For platform services that are new to Longhorn, their only public API will be in WinFX. There may be corresponding undocumented system calls used by WinFX (just as there are today for many Win32 APIs) but there is no reason for there to be an equivalent new public Win32 API; Longhorn can cut out the middle man and have WinFX make system calls directly. In the long term, we may even see Win32 relegated to an isolated subsystem just as the old 16-bit world is today, only supported for the benefit of legacy applications that still depend on it. We have seen this kind of transformation where the wrapper and the underlying API swap places once before in Windows. Remember Win32s include a set of wrappers for the Windows 3.1 API, enabling 32-bit applications to run on 16-bit systems. In some ways, the current .NET Frameworks are reminiscent of Win32s: they allow applications to use the new API even though the underlying OS is fundamentally rooted in the old way of doing things. Over time, we saw DOS and 16-bit Windows cease to be the underlying platform, while Win32 transformed from a wrapper into a native API. WinFX marks the start of a similar transition, with .NET turning from a wrapper into the native API. .NET need not be a set of wrappers any more than Win32 needs to be a set of wrappers for 16-bit versions of Windows.
Pure Managed Functionality
The ability of WinFX to link directly to system services, bypassing Win32, is not the only way in which new Longhorn features can be exposed in WinFX but not Win32. Many features will be implemented entirely in managed code with no need for any help from lower levels of the platform at all.
There are already many examples of pure managed features in the shipping versions of .NET Framework. For example, you can make extensive use of the XML functionality in the current versions of .NET without the framework ever making a call into Win32. Likewise, although ASP.NET integrates with IIS in the Win32 world, the vast majority of the value that it adds over the unmanaged ISAPI extension mechanism is implemented in managed code. The ASP.NET page caching mechanism has no Win32 equivalent, neither do the key parts of its object model. (HttpRequest, HttpResponse, and friends may look reminiscent of the classic ASP objects, but they are not wrappers. They were designed to look very similar to the ASP object, in order to ease the transition to ASP.NET, but they are all implemented entirely in managed code.)
The same will be true for much of the new functionality in Longhorn. There will, of course, be some things which involve new platform features all the way from WinFX's public API right down to kernel mode-- the new 'Avalon' graphics model being the most obvious example. However, there will be many more features implemented entirely in managed code. For example, although Avalon relies on platform support at all levels for performance reasons, a considerable amount of its functionality will reside entirely in managed code. (It would be rather inefficient if every single interaction your code had with Avalon objects caused calls all the way down into the lowest levels of the OS.)
Conclusion
To view the .NET Framework as being merely a wrapper around Win32 is to ignore a large part of the benefit that it offers. Even with the versions shipping today, there is a considerable amount of functionality that is implemented entirely in managed code. This will be true to an even greater extent in WinFX on Longhorn. Moreover, where new features require support from the lower layers of the platform, WinFX will not need to have a Win32 API that it can wrap, as it will be able to use the low-level system API directly, just as Win32 does today. For anyone writing Windows applications today, the message is clear: managed code is the way of the future.
Ian Griffiths is an independent consultant specializing in medical imaging applications and digital video. He also works as an instructor, teaching courses on .NET for DevelopMentor. Ian holds a degree in computer science from Cambridge University.
Return to ONDotnet.com
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 11 of 11.
-
.NET, Windows API and C
2004-03-24 00:20:30 anatolk [Reply | View]
Ok, i'm working intensively with the Windows API
for 6 years and i can tell that it's a very good API (for those who strain their brains to understand it), it's simple, elegant and implemented in a simplest programming language that is C. I've never seen something that can't be done with it. I'm watching all this hysteria around new .NET technology and scratching its internals to see where this propagated "simplicity and benefits" of .NET programming sits, but all i find is an unnecessary complexity, obscurity and overhead. And over and over i see the same articles "How to make a color button...", "How to fill a list with values...", "How to get number of drives...",etc. but now with "...using .NET" appended at the end. And what is really bad is that in M$ Windows developers every time need to learn all the old things in a "new way, new paradigm". We've seen OLE, COM, ActiveX, VB way, MFC way, now we see .NET. Now the all cure word is "fully object oriented" and is very tied to things like .NET and Java. Well, OO is not a technology but a paradigm, Windows itself is a fully object oriented system from its beginning, and not to say Windows but even the Presentation Manager, its API is fully object oriented, the NT kernel is also fully object oriented and is written in plain C. The C language is NOT a procedural language, it is a general purpose language and that's why OS-es are written in it. It provides the necessary building blocks for an object oriented system. Its simplicity of programming and power shines more than 30 years. Well, i'm not going to discuss here the birth of "new" technologies(products,"paradigms",etc.) and M$ sales;). I am a hardcore Windows programmer, but what i'm really disappointed now is that i can't see my future in the Windows world az a C programmer(it's a bit paradoxical, since C programmers were most valuable in the OS world). Ok, we now stick with all managable code, but how can a C programmer fit in that world? When Apple released their completely rewritten new os MacOS X, they provided new API's like Cocoa but they retained the old Carbon C flat API and not only for compatibility but it can access all the new funccionality of the OS and it is not considered an "old fashioned, outmoded, arcane" API but is considered a valuable API with a future. Now existing C programmers can apply their existing knowledge and simply expand it with the new OS features, making them even more productive. I didn't see such a choice in the future of Windows.
-
Some doubts
2004-01-15 04:45:15 anonymous2 [Reply | View]
Hello,
Great articule, but I how some doubts that I want to comment with you all . When information is received from an untrusted source it must be validated prior to processing it. In the case of the aforementioned talkd hole, the daemon should have made sure the path to the terminal file was indeed correct. This could have been done by simply checking the password database, making sure the ownership matched, and that the terminal path did indeed point to a terminal. Later in the FAQ, the concept of the least privilege principle is explained, and it would have worked wonders with the aforementioned security hole.
Many Thanks
Tarik
Computer Science Dep.
Tanzania University
___________________________________________________________
Try Free Mail, best translator resources in with [Africa]
For Europe: [France] [Germany] [Italy][ Portugal] [Spain]
-
Hello World in WinFx?
2004-01-09 22:56:58 anonymous2 [Reply | View]
How to write a simple "Hello World" program in WinFx?
-
PeekMessage,DispatchMessage
2003-12-09 09:18:22 anonymous2 [Reply | View]
You haven't answered the primary question anyone asks about a platform that would not use WIN32. That's the question of windows and message pumps. When you know how much anything works with it, including sockets ( :-) ), where are the message pumps gone.
The marketing brochure says Avalon works without message pumps.
This cannot be true (it's marketing after all), otherwise this would also completely and utterly obsolete anything Windows-like. In other terms, no pre-Longhorn app would be able to run on a Longhorn OS.
So the message pump is still there, it's just hidden (like the UI thread in winforms).
That being said, control over the message pump is critical for many apps, so if the new framework doesn't provide any direct/indirect level of control over it, I am afraid that it will be very hard to come up with high performing and well-behaving apps that would at the same time be nice citizens to the overall CPU and system loads.
My 0.5 cent.
Stephane Rodriguez.
-
Other platforms?
2003-12-08 07:07:59 rrevo [Reply | View]
Since newer longhorn features will be implemented in the .net api, will all applications c++, java have to run within the .net vm ? I mean excluding present win32 code and lower level calls etc. In other words will .net be the only platform for application development in winfx ?
-
What Managed Means...
2003-11-26 08:45:34 Shawn Wildermuth |
[Reply | View]
Managed is a term that specifically means that the memory of the code is managed by some runtime environment. In the case of .NET code (and WinFX specifically), the garbage collector managed the memory.
In Win32, the API is unmanaged and exposed to .NET clients through interop. To .NET clients, it is still unmanaged memory and has the same constraints as any system that has unmanaged memory (possibly of memory leaks, no code-access security, etc.) By the WinFX being all managed, the .NET folks get to use the API in a more native way, but those same API's will be exposed to Win32 folks throuth interop the other way around. The code will continue to be managed, but the calling code may not be managed (in the case of calling it from a traditional MFC app for example).
HTH
Shawn Wildermuth
Editor of ONDotnet.com
-
Great, but what is "managed" ?
2003-11-26 08:33:33 anonymous2 [Reply | View]
"Managed" is a word that is used very often in .Net land, but seldom defined. If managed = .Net code, then yes, I would expect win32 is "unmanaged".
I would expect "managed" code to mean more than being .Net compatible - what does code management mean, or is this just doublespeak to make us think that win32 has mysteriously become obsolete ?






but you forgot one thing - it is technology...
on the other hand there is marketing...
I have wrote 3 programs (one project with MFC). all they together fit on HD less then 10 MB . Instalation - as copying files and configuring something - takes several seconds. So I desided it is wrong way.
Find out some BMP, put them in dll, made some useless catalogs, files... Then found MS tool for making instalation. The process of instalation become 3-5 min.
The clients look at the program, enjoy it (there was functions, witch he needs) and ask me: how much does it fit on HD?
I said:
-50 MB.
-oh, it is very small program...
also, i have talked with some sale managers. They do not know about software. They know one thing: if soft do not take 200MB - it is not software.
...
Microsoft help for us, and it do marketing also.
Who needs fast, good programed softeware?
It meens: you can work with PII 64MB...
is it computer?
(and even no needs for new, better, faster,etc!!...)