Board index » delphi » Can anyone please help me code the IEnumSTATPROPSETSTG Next method?
Andrew Fiddian-Green
![]() Delphi Developer |
Can anyone please help me code the IEnumSTATPROPSETSTG Next method?2008-08-02 06:02:01 PM delphi270 Can anyone please help me in coding an implementation of the IEnumSTATPROPSETSTG Next method? MSDN ( msdn.microsoft.com/en-us/library/aa379213(VS.85).aspx ) describes it as follows: The Next method retrieves a specified number of STATPROPSTG structures, that follow subsequently in the enumeration sequence. HRESULT Next([in] ULONG celt, [out] STATPROPSTG* rgelt, [out] ULONG* pceltFetched); Parameters celt The number of STATPROPSTG structures requested. rgelt An array of STATPROPSTG structures returned. pceltFetched The number of STATPROPSTG structures retrieved in the rgelt parameter. QUESTION 1 My implementation stub is as follows. It compiles OK, but fails with a memory access fault when I try to assign something to the array. Can anyone please tell me what I am doing wrong? ++++ function Txx.IEnumSTATPROPSETSTG_Next(celt: ULONG; out rgelt; pceltFetched: PULONG): HResult; type TStatPropSetStgArray = array of TStatPropSetStg; PStatPropSetStgArray = ^PStatPropSetStgArray; var lArray: PStatPropSetStgArray; hnd: THandle; begin // get some memory hnd := GlobalAlloc(GHND, celt * sizeof(TStatPropSetStg)); // lock it lArray := GlobalLock(hnd); // try to use the array -- FAILS !! lArray^[0].fmtid := ... <= Access Violation!! ++++ QUESTION 2 There is a discrepancy between the wy that Delphi declares the interface in ActiveX and the way Microsoft describes it on MSDN Delphi ActiveX declaration: function Next(celt: ULONG; out rgelt; pceltFetched: PULONG): HResult; stdcall; Microsoft declaration: HRESULT Next([in] ULONG celt, [out] STATPROPSTG* rgelt, [out] ULONG* pceltFetched); Because of this, I don't know what is the correct way to return the data array in the Delphi defined untyped out parameter "rgelt". My code is as follows. Is it correct? // return the out parameter PStatPropSetStgArray(rgelt) := lArray; Thanks in advance... |