473,624 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert SafeArray to managed array

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
5 6344

"Maxim" <vmu-at-mail-dot-ruwrote in message
news:Ot******** ******@TK2MSFTN GP04.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
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.org wrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>
"Maxim" <vmu-at-mail-dot-ruwrote in message
news:Ot******** ******@TK2MSFTN GP04.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

"Maxim" <vmu-at-mail-dot-ruwrote in message
news:%2******** ********@TK2MSF TNGP03.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
>
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 multidimentiona l SAFEARRAY
is a little bit clumsy, so I thought that there is a more effective way.
Apr 12 '07 #5

"Maxim" <vmu-at-mail-dot-ruwrote in message
news:uQ******** *****@TK2MSFTNG P06.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 multidimentiona l
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13430
by: Ken Layton | last post by:
Attempting to pass a VBScript Array of Bytes to a C# Managed COM object has resulted in some very undesirable and strange behavior. When definining a method in my C# COM class as "void Write(byte bBytes)" or "void Write(byte bBytes, int nLen)" or "int Write(byte bBytes, int nLen)"VBScript returns a "Invalid procedure call or argument" exception. However when I define the method as "int Write(byte bBytes)" it works just fine. Unfortunately...
4
10313
by: Roland Moschel | last post by:
Hi there ! I have some Problems to get a SafeArray out of a COM Server written in (Unmanaged) C++. From (unmanaged) Visual Basic , everything is ok , but unfortunately in C# I get an exception. Can anybody help me ?
5
6925
by: Tronster Hartley | last post by:
I've written an ATL 7.1 component and have a C# 1.1 client that is consuming it. The ATL component has a method with a that returns a SAFEARRAY of INTs, but my C# component chokes on it. The C# code: // Display a message box with a value from the ATL control private void GoButton_Click(object sender, System.EventArgs e) {
10
11119
by: thinktwice | last post by:
in my script file , i need call a method of a atl com module(implemented in vc++), which returan an safearray. i don't know how to convert it into array in jscript. i have tried serveral ways to get each item but failed at last. could anyone help me?
1
6013
by: Brendan Grant | last post by:
I’ve got a C# library that I’ve built into a COM component that will be used from a VC++ 6 application and while the creation of the COM object side of things seem to be working fine, using the object fully is another matter. On the C# side of things I’ve got an object defined like so: public class PID : IPID { private string type;
1
2825
by: Christian Schmidt | last post by:
Hi all, I need to implement an unmanaged function that gets a SafeArray and hands it over to a managed function having the managed array-type. Using MarshalAs I can call unmanaged functions having SafeArray from managed code. But here I need this vice-versa... I assume it is doable with MarshalAs magic, but how? Thanks Christian
2
4135
by: Simply_Red | last post by:
I'm using VC6. i have a DLL written in VC6 and used by VB6( and VBA Excel), i use SafeArray as parameter, the array is created(declared), in VB and C++ fill it. now i need VC++ to get an array of array of different sizes, and VB can't know the size of these arrays, so the arrays will be 'created' in VC. here the code that i use(and it crashes):
4
6540
by: Steven Blair | last post by:
I have some C++ code which creates a SafeArray and passes it to my C# dll using COM: SAFEARRAY *psaOut = SafeArrayCreateVector(VT_BSTR, 0, 3); VARIANT pVarOut; VariantInit(&pVarOut); pVarOut.vt = VT_ARRAY | VT_BSTR; pVarOut.parray = psaOut;
0
3216
skeptics
by: skeptics | last post by:
Trying to pass a SafeArray that i get form Request.BinaryRead Method in classic asp to a c# com interop component. In this thread i found a solution to pass and cast a normal asp safearray in to a c# array: http://bytes.com/groups/net/114755-passing-safearray-bytes-vbscript-managed-com-object-c#goto_threadtools but no matter what i try. i cant pass a array that i get from Request.BinaryRead Method in to the component. i always get a error...
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.