PRB: Visual Basic Does Not Understand IUnknown** TypeID: Q194913
|
When writing a COM component in C++, it may be necessary to declare a function parameter as being the type IUnknown**. However, if the interface is defined in IDL and compiled with MIDL, Visual Basic will not understand the declaration and will display the type as "Unknown" in the Object Browser.
Visual Basic can accept parameters as type IUnknown**, but they must be
qualified with the stdole library that defines the IUnknown interface
(i.e., stdole.IUnknown**), and the type library should be compiled with
MkTypLib instead of MIDL.
NOTE: Adding stdole.IUnknown** to your interface means that it no longer
adheres to the strict standards of being OLE Automation compatible. For
your library to compile correctly, you may need to remove any interface
attributes that cause MkTypeLib to perform strong type checking, including
the oleautomation, dual, and non-extensible keywords.
This behavior is by design.
[
uuid(1A4C3A6A-50AE-11D1-BB71-00C04FAD8B08),
version(1.1)
]
library MyUnknown
{
importlib("StdOle2.tlb");
[
odl,
uuid(1A4C3A68-50AE-11D1-BB71-00C04FAD8B08),
hidden
]
interface _CTUnknown : IUnknown {
HRESULT GetIUnknown([out, retval] IUnknown** iu);
HRESULT SetIUnknown([in, out] IUnknown** iu);
};
[
uuid(1A4C3A69-50AE-11D1-BB71-00C04FAD8B08)
]
coclass CTUnknown {
[default] interface _CTUnknown;
};
};
HRESULT GetIUnknown([out, retval] stdole.IUnknown** iu);
HRESULT SetIUnknown([in, out] stdole.IUnknown** iu);
mktyplib MyUnknown.odl /tlb "Debug\MyUnknown.tlb"Then add the following to the Output file(s) line and click OK:
Debug\MyUnknown.tlb
Keywords : kbCOMt kbVBp kbVBp500 kbVBp600 kbVC500 kbVC600 kbCodeSam
Version : WINDOWS:5.0,6.0; WINNT:5.0,6.0
Platform : WINDOWS winnt
Issue type : kbprb
Last Reviewed: May 27, 1999