如何获取某些 Visual Basic 6 控件的 IUnknown* 指针(如果有)?
我想从 Visual Basic 6 程序中调用一些带有 IUnknown*
的 C 函数。假设我知道 VB6 应用程序中的某些控件是 ActiveX 控件,我可以从中获取底层的 IUnknown*
(也许通过强制转换?)将其传递给 C 函数吗?
I'd like to call some C functions from a Visual Basic 6 program which take an IUnknown*
. Assuming that I know that some control in my VB6 application is an ActiveX control, can I get the underlying IUnknown*
out of that (maybe by casting?) to pass it to the C function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有 COM 接口均派生自
IUnknown
,您可以在任何有效的接口指针上使用IUnknown
方法。如果您需要对同一组件的额外引用,但不关心哪个接口,则使用
IUknown
的 QueryInterface 方法。All COM interfaces derive from
IUnknown
, you can just use theIUnknown
methods on any valid interface pointer.If you need an additional reference to the same component, but don't care about which interface then use the
QueryInterface
method forIUknown
.与此同时,我发现了一件有趣的事情(只是提一下,以防有人发现这个问题):对于我测试的许多控件,
GetWindowLong
返回的GWL_USERDATA
值生成地址某些结构的IUnknown
指针值位于偏移量 12 处。因此,以下内容可能对您有用:似乎许多控件都在
GWL_USERDATA
给出的地址处存储了相同的结构。也许对于所有 Visual Basic 控件都是如此?One interesting thing I found out in the meanwhile (just mentioning it in case somebody finds this question): for many controls I tested, the
GWL_USERDATA
value returned byGetWindowLong
yields the address of some struct which has theIUnknown
pointer value at offset 12. So the following may work for you:It seems many controls have the same struct stored at the address given by
GWL_USERDATA
. Maybe it's true for all Visual Basic controls or so?