> Hi all,
>
> I'm calling a COM Interface method that returnes SafeArray wrapped into
> variant. Is it possible to convert it to managed array? Because working
> with SAFEARRAY directly is a bit complicated. Or maybe there is a managed
> wrapper class for safe array?
A SAFEARRAY of what? Usually the COM Interop that is normally generated when
you references the COM object can convert SAFEARRAY parameters to their
managed counterpart. For example a SAFEARRAY of elements of type VT_I2 will
convert to short[], etc.
Brian
Maxim - 11 Apr 2007 07:52 GMT
Thank you for your reply, Brian.
The point is that I'm using #import directive, to generate wrappers for COM
interafces. This is because there are some problems with using Add
Reference. So after importing I have unmanaged wrappers that make use of
SAFEARRAY. So now I want to convert them to managed classes to simplify the
usage.
BTW I need to convert SAFEARRAY of BSTRs
>> Hi all,
>>
[quoted text clipped - 9 lines]
>
> Brian
Brian Muth - 11 Apr 2007 17:09 GMT
> Thank you for your reply, Brian.
>
[quoted text clipped - 4 lines]
> the usage.
> BTW I need to convert SAFEARRAY of BSTRs
In that case you can simply use the unmanaged code to fetch the SAFEARRAY
and directly extract the BSTR members. Converting from BSTR to String^ is a
very straightforward step that you can google for if you don't know how.
Brian
Maxim - 12 Apr 2007 10:27 GMT
> In that case you can simply use the unmanaged code to fetch the SAFEARRAY
> and directly extract the BSTR members. Converting from BSTR to String^ is
> a very straightforward step that you can google for if you don't know how.
That's the way I'm doing it now. But fetching of multidimentional SAFEARRAY
is a little bit clumsy, so I thought that there is a more effective way.
Brian Muth - 12 Apr 2007 17:19 GMT
>> In that case you can simply use the unmanaged code to fetch the SAFEARRAY
>> and directly extract the BSTR members. Converting from BSTR to String^ is
[quoted text clipped - 4 lines]
> SAFEARRAY is a little bit clumsy, so I thought that there is a more
> effective way.
You might take a look at the CComSafeArray class, although personally I
never use it.
Brian