"Maxim Fridental" <
[hidden email]> wrote in message
news:b3kogn$1n9mi7$
[hidden email]...
> Hallo,
>
> I have to use one specific DLL function, that gives me back a pointer to
an
> instance of a COM interface (inherited directly from IUnknown), that is, a
> pointer to the virtual table. How can I create an IUnknown (for instance)
> using this pointer?
> Thanks.
How does it return the interface pointer? If via an output parameter (the
normal COM practice), then follow a similar pattern to
ShellLibrary>>allocator, i.e.
answer := IMalloc newPointer.
self SHGetMalloc: answer.
If the function returns a COM interface pointer, i.e. it is declared
something like this:
getInterface
<stdcall: IUnknown* GetInterface>
then you should call it like this:
answer := MyDLL getInterface.
answer beFinalizable.
The #beFinalizable is necessary (in D5, though it won't be in D6), because
the VM's external call primitive can correctly construct ExternalStructure
references, but doesn't (in D5) handle COM interface pointers specifically,
and so doesn't know to mark the object as finalizble so that the reference
count can be released when it is GC'd.
In both cases it is assumed that the called function has already increased
the reference count of the interface pointer it has returned (which is the
COM convention). If you have an un-ref. counted raw pointer, you can use
IXXXX>>fromAddress: to convert it into the appropriate interface class, and
add a reference.
Of course once you have an IUnknown, you can use #queryInterface: <class> to
"cast" it to another interface type.
Regards
Blair