Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

Convert SafeArray to managed array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maxim - 10 Apr 2007 13:51 GMT
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.
Brian Muth - 10 Apr 2007 16:24 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.