I’m having pretty abnormal work in my application. I’m using following code to enumerate all namespaces and some root namespaces – such as Nethood work pretty slow – over one minute to load (!!) That happens only on Win7, on older system loading is OK.
I’m using this functions, from MustangPeak library:
function TNamespace.EnumerateFolder(MessageWnd: HWnd; Folders, NonFolders,
IncludeHidden: Boolean; EnumFunc: TEnumFolderCallback;
UserData: Pointer): integer;
var
Enum: IEnumIDList;
Flags: Longword;
Fetched: Longword;
Item: PItemIDList;
Terminate: Boolean;
OldError: integer;
OldWow64: Pointer;
begin
Result := 0;
OldError := SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX);
try
if Assigned(ShellFolder) then
begin
if Assigned(EnumFunc) then
begin
Terminate := False;
Flags := 0;
if Folders then
Flags := Flags or SHCONTF_FOLDERS;
if NonFolders then
Flags := Flags or SHCONTF_NONFOLDERS;
if IncludeHidden then
Flags := Flags or SHCONTF_INCLUDEHIDDEN;
// --- This is new added
Flags := Flags or SHCONTF_ENABLE_ASYNC;
if Valid then
begin
OldWow64 := Wow64RedirectDisable;
try
if ShellFolder.EnumObjects(MessageWnd, Flags, Enum) = NOERROR then
begin
// Vista Enum is nil every once in a while
if Assigned(Enum) then
begin
while (Enum.Next(1, Item, Fetched) = NOERROR) and not Terminate do
begin
if EnumFunc(MessageWnd, Item, Self, UserData, Terminate) then
Inc(Result)
end
end
end
finally
Wow64RedirectRevert(OldWow64)
end
end
end
end
finally
SetErrorMode(OldError);
end
end;
Now I read in MSDN doc that in Win7 new async flag has been supported in order to get results instantly but then to receive other results when system read it.
That flag is called SHCONTF_ENABLE_ASYNC and I added it in code on place I’ve marked with (// — This is new added)
Problem is because I don’t know how to catch events when I receive updates.
How to hook on newly received items? Is there some event (message etc.) that system (object) sends to some control or structure etc.
Thanks!
SHCONTF_ENABLE_ASYNCdoes not make the enumeration itself asynchronous. It simply letsIShellFolderknow that you are monitoring for asynchronous change notifications outside ofIShellFolder, such as withSHChangeNotifyRegister(), so the enumeration does not need to return everything at one time as the change notifications will let you know when items are added/removed/changed in real-time.