Convert SafeArray to managed array

  • Thread starter Thread starter Maxim
  • Start date Start date
M

Maxim

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?

Thanks in advance.
 
Maxim said:
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
 
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


Brian Muth said:
Maxim said:
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 said:
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

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
 
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.
 
Maxim said:
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.

You might take a look at the CComSafeArray class, although personally I
never use it.

Brian
 
Back
Top