简体   繁体   English

用C ++编写的Windows编程

[英]Windows Programming in C++

Being a C#/Java programmer, I really need to know a fact: Has Windows Programming with Win32SDK/MFC/wxWidget become antiquated? 作为一名C#/ Java程序员,我真的需要知道一个事实:使用Win32SDK / MFC / wxWidget的Windows编程是否已经过时了?

What is the status of popularity of these technologies in software industry now? 现在这些技术在软件行业的普及程度如何?

Being a C#/Java programmer, do I need to learn Win32SDK/MFC/wxWidget now? 作为一名C#/ Java程序员,我现在需要学习Win32SDK / MFC / wxWidget吗?

I think that learning the Win32 SDK is useful because it helps you understand how Windows works internally. 我认为学习Win32 SDK很有用,因为它可以帮助您了解Windows内部的工作方式。 I found learning about hooks and subclassing very fascinating. 我发现学习钩子和子类非常有趣。 So if it interests you then you should go for it. 所以,如果它感兴趣你那么你应该去做。 However, you probably don't need to know Win32. 但是,您可能不需要知道Win32。 It's not yet antiquated today but it may be in the future. 它今天还没有过时,但它可能在未来。

I never had much interest in MFC because it requires the paid version of Visual Studio. 我从未对MFC感兴趣,因为它需要付费版本的Visual Studio。

I think Win32/64 SDK will never be antiquated, as drivers or other low level programs won't be written in .NET or Java because of the performance requirements. 我认为Win32 / 64 SDK永远不会过时,因为性能要求不会用.NET或Java编写驱动程序或其他低级程序。 If you are going to develop in .NET, then MFC or wxWidget is useless for you. 如果你要在.NET中开发,那么MFC或wxWidget对你来说毫无用处。

I develop in .NET regularly, and sincerely, every program I've ever created in .NET called some Win32 API functions. 我定期在.NET中开发,并且真诚地,我在.NET中创建的每个程序都称为一些Win32 API函数。 So learning Win32/64 SDK isn't pointless, but is time-consuming. 所以学习Win32 / 64 SDK并不是没有意义的,但是很耗时。

Yes, learn Win32, even if don't ever intend to write or maintain C/C++ apps. 是的,学习Win32,即使不打算编写或维护C / C ++应用程序。

No, don't bother learning MFC/wxWidget now. 不,现在不要费心学习MFC / wxWidget。 MFC does come with its source code, so you can study how some classes implement wrappers for Win32, but that is more interesting to C++ programmers. MFC确实附带了它的源代码,因此你可以研究一些类如何为Win32实现包装器,但这对C ++程序员来说更有趣。 MFC is has decreased in popularity, though Visual Studio continues to support this older tech. 虽然Visual Studio继续支持这种旧技术,但MFC的受欢迎程度有所下降。 Learn MFC/wxWidget only for an as-needed basis, if you need to maintain some older code. 如果您需要维护一些旧代码,请仅在需要的基础上学习MFC / wxWidget。

With C#/Java, you can solve a lot of problems, but there are times when you will need to use Win32 directly to achieve some task. 使用C#/ Java,您可以解决很多问题,但有时您需要直接使用Win32来完成某些任务。 for a variety of reasons. 由于各种原因。 Maybe some functionality is simply missing from .NET/Java, or has a bug that can be avoided by going directly to Win32. 也许.NET / Java中缺少某些功能,或者有一个可以通过直接转到Win32来避免的错误。 Maybe your particular problem to solve has unusual or strict requirements, and you would consider writing a portion of your app in native code using some Win32 calls as necessary. 也许您要解决的特定问题有不寻常或严格的要求,您可以考虑根据需要使用一些Win32调用在本机代码中编写应用程序的一部分。 Lots of examples/situations really. 真的有很多例子/情况。

Another reason to learn Win32 is that both .NET/Java are higher level abstractions (which is in itself a good thing), but it really does help to understand the internals for these reasons: 学习Win32的另一个原因是.NET / Java都是更高级别的抽象(这本身就是一件好事),但由于以下原因,它确实有助于理解内部:

  1. You get an appreciation of how much work .NET/Java do for you. 您了解.NET / Java为您做了多少工作。 Of course, you can do the same things in C/C++, but it takes a lot more work. 当然,你可以在C / C ++中做同样的事情,但它需要做更多的工作。 Consider these two compelling .NET technologies, WPF and WCF, which do a lot work for you. 考虑这两个引人注目的.NET技术,WPF和WCF,它们为您做了很多工作。
  2. You will better understand resource management. 您将更好地了解资源管理。 Specifically, both .NET/Java are garbage collected environments, but you must deterministically release OS resources (explicitly calling Dispose), for such things as network connections, window handles, kernel objects, and plenty more. 具体来说,.NET / Java都是垃圾收集环境,但您必须确定性地释放OS资源(显式调用Dispose),例如网络连接,窗口句柄,内核对象等等。 You should never rely on the garbage collector to release these objects for you, since the GC is non-deterministic. 您永远不应该依赖垃圾收集器为您释放这些对象,因为GC是非确定性的。
  3. Debugging, knowing the internals seriously helps here. 调试,知道内部严重有帮助。
  4. Knowing Win32 can sometimes help explain the API design in .NET at least. 知道Win32有时可以帮助解释.NET中的API设计。 Some parts of the .NET API are modeled on Win32 API, but some parts of the .NET API are extreme improvements over some truly heinous Win32 API designs (consider the API for using GDI for example). .NET API的某些部分是在Win32 API上建模的,但.NET API的某些部分比一些真正令人发指的Win32 API设计有了极大的改进(例如,考虑使用GDI的API)。
  5. Finally, knowing Win32 can help solve performance problems in your apps. 最后,了解Win32可以帮助您解决应用中的性能问题。

Win32 won't become antiquated, until the Microsoft's popular operating systems are based on something else. 在Microsoft的流行操作系统基于其他东西之前,Win32不会过时。 At one point, Microsoft was going to replace Win32/64 with .NET in Vista, but this didn't pan out. 有一次,微软将在Vista中用.NET取代Win32 / 64,但这并没有成功。 Even for whatever replaces Win32/64 is the future, you still need to understand the OS SDK. 即使对于未来取代Win32 / 64的任何内容,您仍然需要了解OS SDK。 At the risk of sounding like a salesman, I will say that learning Win32 will in fact help you write more robust applications and will greatly aid your debugging skills, two important items to help you stay employed. 冒着听起来像推销员的风险,我会说学习Win32实际上会帮助你编写更强大的应用程序,并将极大地帮助你的调试技能,这是帮助你保持就业的两个重要项目。 I would never hire a windows programmer who doesn't have at least some experience with Win32. 我永远不会雇用一个没有至少一些Win32经验的Windows程序员。

I would suggest "Windows via C/C++" by Richter/Nasarre, as one example of a good book on Win32 (yes, it's obviously geared towards C/C++, but these authors do an excellent job explaining Win32). 我建议使用Richter / Nasarre的“Windows via C / C ++”作为Win32上一本好书的一个例子(是的,它显然是针对C / C ++,但是这些作者在解释Win32方面表现非常出色)。

Hope this helps. 希望这可以帮助。

I am an architect and I recommend that all new projects use newer technologies, like .NET or Java. 我是一名架构师,我建议所有新项目都使用更新的技术,如.NET或Java。 The difference in productivity is tremendous, at least according to my own experience with C++ and .NET. 生产力的差异是巨大的,至少根据我自己的C ++和.NET经验。

There are two exceptions: - I work for a software company and we are bound by the requirements of our customer, usually including the programming environment. 有两个例外: - 我为一家软件公司工作,我们受到客户要求的约束,通常包括编程环境。 So, if a customer only has people knowing, say, MFC, we will make an MFC project. 因此,如果客户只知道MFC,我们将制作一个MFC项目。 But this is becoming rarer and rarer. 但这变得越来越罕见。 If we have the choice, we will go with .NET or Java. 如果我们有选择,我们将使用.NET或Java。 - You have a team with expert people in these older technologies and they are quite productive with them. - 您拥有一支拥有这些旧技术专家的团队,他们的工作效率很高。

There's plenty of work for people like you, so I'd advise not learning these for job purposes. 对于像你这样的人来说,有很多工作要做,所以我建议不要为了工作目的而学习这些。 We have some MFC apps, but that's partly because it's what we had and partly because we had more faith in C++ performance, and performance is very important for them. 我们有一些MFC应用程序,但这部分是因为它是我们拥有的,部分是因为我们对C ++性能更有信心,而性能对他们来说非常重要。

I wouldn't call C++ or MFC antiquated, but there's relatively less new work in it. 我不会把C ++或MFC称为过时的,但它的新工作相对较少。 (I would very much like to never support another Win32 program, though.) The new C++ standard should be out in 200B, and people will continue to work on it, and Microsoft has been adding new classes to MFC, so obviously there's continued interest and continued work. (我非常希望永远不会支持另一个Win32程序。)新的C ++标准应该在200B以外,人们将继续努力,而且微软一直在为MFC添加新的类,所以显然有持续的兴趣并继续工作。

For professional development, I'd suggest you learn something different, but that would be something like Lisp or Haskell, rather than C++, and as far as I can tell there's no particular virtue in knowing MFC. 对于专业开发,我建议你学习一些不同的东西,但那就像Lisp或Haskell,而不是C ++,据我所知,在了解MFC方面没有特别的优点。

Realistically Microsoft forces business to use their latest and greatest technologies. 实际上,微软迫使企业使用他们最新和最好的技术。 There will always be work for someone who knows both technologies because someone has to port legacy code. 对于知道这两种技术的人来说总会有工作,因为有人必须移植遗留代码。

Many small devices (phones) or games require lighter solutions. 许多小型设备(手机)或游戏需要更轻的解决方案。 If you intend to work in those areas you will definitely need those technologies. 如果您打算在这些领域工作,您肯定需要这些技术。

You need to decide where you want to go. 你需要决定你想去哪里。 Once you have a map then you can lay in the right supplies for the journey. 一旦你有了地图,那么你可以为旅程提供合适的物资。

I found Java horrendous to work with compared to Win32. 与Win32相比,我发现Java可怕。 Someone needs to cut about ninety percent of the inbuilt libraries. 有人需要削减大约百分之九十的内置库。

I wouldn't call Win32 and such antiquated. 我不会打电话给Win32这样陈旧的。 As other people have said, it really depends on the app. 正如其他人所说,这实际上取决于应用程序。 As a game developer, I use Win32 less and DirectX a hell of a lot more. 作为游戏开发者,我使用的是Win32,而DirectX则更多。 I could double or triple my Windows code, and it would still be an extremely small portion of the project. 我可以将我的Windows代码加倍或加倍,它仍然只是项目的一小部分。

However, if you're writing a primarily interface application with a relatively small and lightweight backend, .NET might well be a good choice for you. 但是,如果您正在编写一个具有相对较小且轻量级后端的主界面应用程序,那么.NET可能是您的不错选择。

As for Haskell, I just found that to be a truly terrible language in pretty much every respect. 至于Haskell,我发现在几乎所有方面都是一种真正可怕的语言。 It seemed to me that it served some abstract mathematical definition of "functional", rather than a real definition of "programmable-in". 在我看来,它提供了一些“功能”的抽象数学定义,而不是“可编程”的真正定义。

Win32 SDK is nowadays used in niche markets, where more modern technologies can't be used for some reasons (legacy Win32 systems, games, system drivers, Windows Embedded systems). Win32 SDK现在用于利基市场,由于某些原因(传统的Win32系统,游戏,系统驱动程序,Windows嵌入式系统)无法使用更多现代技术。 If you aren't planning on pursuing a career on these markets, I wouldn't bother learning Win32 now. 如果你不打算在这些市场上谋求职业,我现在不会费心去学习Win32。 It is not that is useless and has no new things to teach you, but let's face it, there are so many new technologies coming out even at the time we speak. 这不是没用的,没有新的东西可以教你,但让我们面对现实,即使在我们说话的时候,也有很多新技术出现。 I have a dozen of technologies/languages in my waiting list to start learning and experimenting with. 我在等待名单中有十几种技术/语言,可以开始学习和试验。 You can certainly find more interesting and more career favorable technologies to learn. 你当然可以找到更有趣,更有利于职业的技术来学习。

Performance critical apps (games) typically use C++ Win32 API. 性能关键应用程序(游戏)通常使用C ++ Win32 API。

C# and .NET are actually built on top of the Win32 API. C#和.NET实际上构建在Win32 API之上。 To access some of the advanced features of Win32 that aren't exposed through C# and .NET you use Pinvoke to manually expose a C Win32 function to your C# app. 要访问通过C#和.NET公开的Win32的一些高级功能,您可以使用Pinvoke手动将C Win32功能公开给您的C#应用​​程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM