how to iterate through C++ safearray pointer to pointer and access its elements.
I tried to replicate the solution posted by Lim Bio Liong
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/022dba14-9abf-4872-9f43-f4fc05bd2602
but the strangest thing is that the IDL method signature comes out to be
HRESULT __stdcall GetTestStructArray([out] SAFEARRAY ** test_struct_array);
instead of
HRESULT __stdcall GetTestStructArray([out] SAFEARRAY(TestStruct)* test_struct_array);
Any ideas?
thanks in advance
Safearrays are created with
SafeArrayCreateorSafeArrayCreateVector, but as you ask about iterating over a SAFEARRAY, let’s say you already have a SAFEARRAY returned by some other function. One way is to useSafeArrayGetElementAPI which is especially convenient if you have multidimensional SAFEARRAYs, as it allows, IMO, a bit easier specifying of the indices.However, for vectors (unidimensional SAFEARRAY) it is faster to access data directly and iterate over the values. Here’s an example:
Let’s say it’s a SAFEARRAY of
longs, ie. VT_I4