C 句柄 - 如何使用它们?
我正在制作的 Dreamweaver 插件的一些文档中有以下内容:
无效**连接数据
• 连接数据参数是 处理代理的数据 希望 Dreamweaver 在何时传递给它 调用其他API函数。
除了手册中有关连接数据的信息外,我没有其他信息。从字面上思考,我认为句柄是指通用句柄,但是我无法找到有关使用 C 通用句柄的文档
HANDLE h = connectionData;
。是否在我的代码中进行编译。我到底如何获得这个数据结构中的“秘密”/有人可以解释一下 C 的通用句柄是如何工作的吗?
I have in some documentation for a plugin for Dreamweaver I am making that says the following:
void **connectionData
• The connectionData argument is a
handle to the data that the agent
wants Dreamweaver to pass to it when
calling other API functions.
I have no other information than this from the manual in regard to connectionData. Thinking literally, I figured handle refered to a generic handle,however I am not able to find documentation on working with generic handles in regard to C.
HANDLE h = connectionData;
Does compile in my code. How exactly do I get the "secrets" inside this data structure/can someone explain how generic handles for C work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,通常你不应该知道句柄的秘密;你应该知道句柄的秘密。它们通常只是指向您正在使用的 lib/API 内部某些内部结构的指针,并且只有 lib 知道如何使用它。
没有通用规则或有关句柄的任何内容,您必须按照库文档的指示使用它们。
Well, usually you are not supposed to get the secrets of handles; they are usually just a pointer to some internal structure inside the lib/API you are using and only the lib will know how to use it.
There is no generic rules or anything about handles, you'll have to use them as indicated by your lib's docs.
按照其定义方式,connectionData 是一个指向某个对象的指针。如果不知道分配给connectionData 的内容,您就无法知道其他任何内容。你的其他语句起作用的原因是 HANDLE 可能是一个扩展为 void* 的宏
要知道“秘密”,你需要找出什么结构(这是一个猜测 - 它实际上可能是任何数据类型)connectionData 点到,然后查看该结构的定义。我不知道您对编程的总体熟悉程度,但调试器允许您在断点处暂停时轻松查看结构体的字段。
然而,正如其他人所说,您可能不想搞乱 this 所指向的内部结构,而只使用 API 调用。
The way that this is defined, connectionData is a pointer to a pointer to something. Without knowing what is assigned to connectionData, you can't know anything else. The reason why your other statement worked is that HANDLE is probably a macro that expands to void*
To know the "Secrets," you would need to find out what struct (this is a guess - it could actually be any data type) connectionData points to, then look at the definition of that struct. I don't know how familiar you are with programming in general but a debugger allows you to easily look at the struct's fields while paused at a breakpoint.
However, as other people have said, you probably don't want to muck with the internals of whatever this points to, and only use API calls.
当 C 开发人员特别想要隐藏内部数据并防止 API 用户乱搞实现时,他们会使用“句柄”数据类型。句柄有时只是一个指针,但也可以是内部查找表的索引。
一般来说,您应该只使用提供的带有句柄的 API 函数,并学习获取句柄的正确方法、了解其生命周期以及完成后如何正确处置它。
C developers use a "handle" data type when they specifically want to hide the internal data and keep API users from monkeying around with the implementation. A handle is sometimes just a pointer, but can also be an index into an internal lookup table.
In general, you should only use provided API functions with a handle, and learn the proper way to get the handle, understand its life cycle and how to properly dispose of it when you're done.