By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,523 Members | 1,938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,523 IT Pros & Developers. It's quick & easy.

Convert SafeArray to managed array

P: n/a
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.
Apr 10 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Maxim" <vmu-at-mail-dot-ruwrote in message
news:Ot**************@TK2MSFTNGP04.phx.gbl...
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
Apr 10 '07 #2

P: n/a
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" <bm***@mvps.orgwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>
"Maxim" <vmu-at-mail-dot-ruwrote in message
news:Ot**************@TK2MSFTNGP04.phx.gbl...
>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


Apr 11 '07 #3

P: n/a

"Maxim" <vmu-at-mail-dot-ruwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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
Apr 11 '07 #4

P: n/a
>
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.
Apr 12 '07 #5

P: n/a

"Maxim" <vmu-at-mail-dot-ruwrote in message
news:uQ*************@TK2MSFTNGP06.phx.gbl...

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.
You might take a look at the CComSafeArray class, although personally I
never use it.

Brian

Apr 12 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.