8

I have

 var H: array of THandle;

then in a loop I create multiple threads, and assign thread handles to the elements of H, and then wait on them. Passing @H[0] as the 2nd parameter to WFMO below works.

WaitForMultipleObjects(Length(H), @H[0], True, INFINITE) <-- Works

But passing @H as below Fails with WAIT_FAILED. GetLastError returns "Invalid Handle".

WaitForMultipleObjects(Length(H), @H, True, INFINITE)  <--- Fails.

Why is @H different from @H[0] ?

Nani
  • 113
  • 5

1 Answers1

8
  1. Because it is a dynamic array, H is already a pointer and it points to the first element, so
  2. @H[0] is the same as H - pointer to the first element
  3. and now @H is equals to @@H[0] - pointer to pointer to the first element.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
zed
  • 798
  • 7
  • 12
  • Thank you. So, if H was declared as `H: array[0..10] of THandle` then @H and @H[0] would be the same, I suppose. I can check it. – Nani Nov 30 '19 at 20:27
  • @Nani Yes, if `H` is a **static array**, than you need to get its address via `@` operator and then `@H` is equals to `@H[0]`. – zed Nov 30 '19 at 20:52
  • You can slso use POINTER(H) to get a pointer to the first element of the dynamic array. – HeartWare Dec 02 '19 at 07:09