什么是C ++中的句柄? [英] What is a handle in C++?

查看:168
本文介绍了什么是C ++中的句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经被告知句柄是一个指针,但不是,它允许你保持对一个对象的引用,而不是对象本身。更复杂的解释是什么?

I have been told that a handle is sort of a pointer, but not, and that it allows you to keep a reference to an object, rather than the object itself. What is a more elaborate explanation?

推荐答案

句柄可以是从整数索引到指向内核空间中的资源。这个想法是他们提供了一个资源的抽象,所以你不需要知道资源本身使用它。

A handle can be anything from an integer index to a pointer to a resource in kernel space. The idea is that they provide an abstraction of a resource, so you don't need to know much about the resource itself to use it.

例如,HWND Win32 API是一个窗口的句柄。它本身是无用的:你不能从它收集任何信息。但传递给正确的API函数,你可以执行丰富的不同的技巧。在内部你可以想到的HWND只是一个索引到GUI的窗口表(这可能不一定是如何实现,但它使魔术有意义)。

For instance, the HWND in the Win32 API is a handle for a Window. By itself it's useless: you can't glean any information from it. But pass it to the right API functions, and you can perform a wealth of different tricks with it. Internally you can think of the HWND as just an index into the GUI's table of windows (which may not necessarily be how it's implemented, but it makes the magic make sense).

编辑:不是100%确定你在你的问题特别是什么。这主要谈论纯C / C ++。

Not 100% certain what specifically you were asking in your question. This is mainly talking about pure C/C++.

这篇关于什么是C ++中的句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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