You are doing something VERY wrong!
First you declare ptrResult as THandle:
ptrResult: THandle;
Later on you cast it to a pointer:
hr := search.ExecuteSearch(LPCWSTR(searchfilter), @AttrArray[0], dwCount, Pointer(ptrResult));
You are actually lucky that it works because a pointer is actually a dword therefore it works but the correct way would IMO be:
ptrHandle: PHandle;
hr := search.ExecuteSearch(LPCWSTR(searchfilter), @AttrArray[0], dwCount, ptrResult);
If you need to pass it as
handle later on use
ptrHandle^
to derefence the pointer.
/Edit just a remark: I know this is just test code but if you change a variable type ALWAYS change it's name as well as you WILL confuse yourself later on ( or DelphiPraxis members reading your code
)
Also when you post example code, please take the effort of cleaning it up as much as possible.