Here we declare a function for any object of specific interface, based on GUID or IID the Interface ID.
For using this type of function we have to pass as first argument the object which have the specific interface.
We don't need to use the IUnknown.QueryInterface, to get the specific object, because the delcaration has the string representation of GUID or IID (or RIID). Here for the example we just use an object with dual interfaces, the IUnkwon and the dispatch. We see how we get the dispatch from IUnkown, using IUknown.QueryInterface passing the specific GUI and the VarPtr(Ptr) which is the pointer how points to memory to place the result. When a new pointer added internal an IUnknown.Addref add one to the accumulator for the number of references. When on reference deleted then the IUnknown.Release called which decrement the number of references and if this number turn to zero then that means no pointer point to object, so the object has to remove from memory, which the code of the object do, erasing the resource which hold (the status of the object).
So the second and third function used to handle the life of the object.
idispatch$="{00020400-0000-0000-C000-000000000046}"
enum IUnknown {
QueryInterface=0
AddRef
Release
}
enum Idispatch {
IUnknown
GetTypeInfoCount
GetTypeInfo
GetIDsOfNames
Invoke
}
DECLARE IUnknown.QueryInterface INTERFACE idispatch$, QueryInterface {long riid, long myptr}
K=List:=1,2,3,4
object Ptr
buffer clear riid as Long*4
return riid, 0:=0x0002_0400, 1:=0, 2:=0xc0, 3:=0x4600_0000
buffer clear myobj as long
? "0x"+hex$(uint(IUnknown.QueryInterface(K, riid(0), varptr(ptr))), 4)="0x00000000"
? type$(ptr)="Inventory"
? len(ptr)=4
? ptr is K = true
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.