How can I get the IUnknown* pointer (if any) for some Visual Basic 6 control?
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?
All COM interfaces derive from IUnknown
, you can just use the IUnknown
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 for IUknown
.
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 by GetWindowLong
yields the address of some struct which has the IUnknown
pointer value at offset 12. So the following may work for you:
IUnknown *unk = (IUnknown *)((char*)GetWindowLong( hwnd, GWL_USERDATA ) + 12);
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?
精彩评论