this is my code to get the IShellFolder interface for any given folder.
the problem is the program will raise an exception (accessing a invalid address) after finished executing this procedure (not inside the procedure!). and one more thing is if i commented out the PROBLEM LINE then it will execute nicely without any exception and there is also no memory leak (somehow the memory allocated to aIShellFolder is free by something, by aDesktopIShellFolder maybe?).
my question is do i need to call the _Release funtion on my aIShellFolder or the IShellFolder is actually a smart pointer? but as far as i know, we can only get a smart pointer if delphi can support operator overloading!
thanks in advance,
ahmoy law
uses
shlobj;
procedure DoSomething ( aFolder: WideString );
var
aDesktopIShellFolder: IShellFolder;
aDesktopPIDL: PItemIDList;
aPIDL: PItemIDList;
aIShellFolder: IShellFolder;
begin
SHGetDesktopFolder ( aDesktopIShellFolder ); // gets the dekstop's IShellFolder
SHGetSpecialFolderLocation ( 0, CSIDL_DESKTOP, aDesktopPIDL ); // gets the desktop's PIDL
aDesktopIShellFolder.ParseDisplayName ( 0, NIL, PWideChar(aFolder), aLen, aPIDL, attrib ); // gets the folder's PIDL
aDesktopIShellFolder.BindToObject ( aPIDL, nil, IID_IShellFolder, aIShellFolder ); // gets the folder's IShellFolder
// do something...
// do something...
// do something...
aIShellFolder._Release; // <-- PROBLEM LINE!!!
TItemIDList.Dispose ( aPIDL );
TItemIDList.Dispose ( aDesktopPIDL );
aDesktopIShellFolder._Release;
end;