为什么 Win32-API 有这么多自定义类型? [英] Why does the Win32-API have so many custom types?

查看:22
本文介绍了为什么 Win32-API 有这么多自定义类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Win32 API 的新手,许多新类型开始让我感到困惑.

I'm new to the Win32 API and the many new types begin to confuse me.

有些函数需要 1-2 个 ints 和 3 个 UINTS 作为参数.

Some functions take 1-2 ints and 3 UINTS as arguments.

  • 为什么他们不能只使用整数?什么是 UINTS?

然后,还有其他类型:

DWORD LPCWSTR LPBOOL 

  • 同样,我认为原始"C 类型就足够了 - 为什么要引入 100 种新类型?
  • 这个很痛苦:WCHAR*

    我不得不遍历它并将每个字符推回 std::string 因为没有其他方法可以将其转换为一个.太可怕了.

    I had to iterate through it and push_back every character to an std::string as there wasn't another way to convert it to one. Horrible.

    • 为什么是 WCHAR?为什么要重新发明轮子?他们本可以使用 char* 代替,或者?
    • Why WCHAR? Why reinvent the wheel? They could have just used char* instead, or?

    推荐答案

    Windows API 最早创建于 1980 年代,多年来必须支持多种不同的 CPU 架构和编译器.它们已经从单用户单进程独立系统转变为联网的多用户多核安全意识系统.他们不得不解决 16 位与 32 位处理器以及现在的 64 位处理器的问题.他们不得不解决 ANSI C 之前的编译器的问题.在早期的非标准化时代,他们不得不支持 C++ 编译器.他们不得不处理分段内存.在 Unicode 出现之前,他们必须支持国际化.它们必须支持与 MS-DOS、OS/2 和 Mac OS 的某种源代码级兼容性.他们不得不在几代英特尔芯片、PowerPC、MIPS、Alpha 和 ARM 上运行.桌面、服务器、移动设备和嵌入式系统使用相同的基本 API.

    The Windows API was first created back in the 1980's, and has had to support several different CPU architectures and compilers over the years. They've gone from single-user single-process standalone systems to networked multi-user multi-core security-conscious systems. They had to work around issues with 16-bit vs. 32-bit processors, and now 64-bit processors. They had to work around issues with pre-ANSI C compilers. They had to support C++ compilers in the early unstandardized times. They had to deal with segmented memory. They had to support internationalization before Unicode existed. They had to support some source-level compatibility with MS-DOS, with OS/2, and with Mac OS. They've had to run on several generations of Intel chips, and PowerPC, and MIPS, and Alpha, and ARM. The same basic API is used for desktop, server, mobile, and embedded systems.

    早在 1980 年代,C 就被认为是一种高级语言(是的,真的!),许多人认为使用抽象类型而不是将所有内容都指定为原始 intcharvoid *.回到我们没有 IntelliSense 和信息提示、代码浏览器和在线文档等的时代,这样的使用提示很有帮助,并且可以更轻松地在不同编译器和不同编程语言之间移植代码.

    Back in the 1980's, C was considered to be a high-level language (yes, really!) and many people considered it good form to use abstract types rather than just specifying everything as a primitive int, char, or void *. Back when we didn't have IntelliSense and infotips and code browsers and online documentation and the like, such usage hints were helpful, and it made it easier to port code between different compilers and different programming languages.

    是的,这是一个可怕的混乱,但这并不意味着他们做错了什么.

    Yes, it's a horrible mess, but that doesn't mean they did anything wrong.

    这篇关于为什么 Win32-API 有这么多自定义类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆