473,786 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Client needs to fetch a string array from a C# COM server.

Hello, I have written a C# COM server that has a few methods and a
property called DataItems that returns an ArrayList. During the
course of execution the ArrayList gets populated with several strings.
I am having issues retrieving these strings from my C++ client.

My C# code looks like this:

public object DataItems
{
get
{return arrListMyList;
}
}
My C++ code looks like this:

VARIANT arrTemp = pMyInterface->GetDataItems() ;

if(arrTemp.vt == (VT_ARRAY | VT_BSTR)){
SAFEARRAY* psa = arrTemp.parray;
long length;
HRESULT hr = SafeArrayGetUBo und(psa,1, &length);
for(long j=0;j<=1;j++)
{
BSTR bstr;
SafeArrayGetEle ment(psa,&j,&bs tr);
CString cs(bstr);

}
}

I think I am going about it the right way, but for whatever reason,
the call to SafeArrayGetBou nds() crashes out. The error message gives
me an Access Violation.

I am basically looking for the easiest way for a C# COM server to
return a string array to a C++ client. I dont _need_ to be returning
an ArrayList. I could make do with an Array or even String[]. If
anyone has any ideas please let me know.
Nov 16 '05 #1
2 3643
BNC,

Why the SafeArray approach - that is for passing arrays of items - and you
are fetching a BSTR, which is a COM type that is supported (it is marshaled
with no other effort required).

Additionally, the BSTR is an array 16 bit unsigned values, and it is also
length prefixed. You can create a BSTR only by calling one of the
Automation system function - SysAllocString, passing in a zero length array
of wchar_t, or by one of the SysAllocString Len derivatives - but never by
hand construction methods. To avoid memory leaks, remember to call
SysFreeString.

Have a look at arrTemp.vt - it should be VT_BSTR, and from that you can
directly access the BSTR as arrTemp.bstrVal ;

Let me know if that does not work.

regards
roy fine
'

"Bnc119" <bn*******@yaho o.com> wrote in message
news:fa******** *************** **@posting.goog le.com...
Hello, I have written a C# COM server that has a few methods and a
property called DataItems that returns an ArrayList. During the
course of execution the ArrayList gets populated with several strings.
I am having issues retrieving these strings from my C++ client.

My C# code looks like this:

public object DataItems
{
get
{return arrListMyList;
}
}
My C++ code looks like this:

VARIANT arrTemp = pMyInterface->GetDataItems() ;

if(arrTemp.vt == (VT_ARRAY | VT_BSTR)){
SAFEARRAY* psa = arrTemp.parray;
long length;
HRESULT hr = SafeArrayGetUBo und(psa,1, &length);
for(long j=0;j<=1;j++)
{
BSTR bstr;
SafeArrayGetEle ment(psa,&j,&bs tr);
CString cs(bstr);

}
}

I think I am going about it the right way, but for whatever reason,
the call to SafeArrayGetBou nds() crashes out. The error message gives
me an Access Violation.

I am basically looking for the easiest way for a C# COM server to
return a string array to a C++ client. I dont _need_ to be returning
an ArrayList. I could make do with an Array or even String[]. If
anyone has any ideas please let me know.

Nov 16 '05 #2
An array of items is exactly what I'm trying to pass back to the C++
client. My C# COM server has an ArrayList containing the following
strings:

foo
goo
zoo

And I need to be able to extract all three strings from the returned
VARIANT object. Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4340
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side vbscript reads the database and populates a listbox on the page with the first field from each record in the recordset. This works fine. - User selects an option on the listbox and, using the OnChange, I
3
2010
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as processor input. The basic class hierarchy is:
5
3445
by: Yossarian | last post by:
I have a handheld running CE .NET 4.2 and I am using c# with framework 1.1 to develop a solution for syncing data that is on the handheld with the local pc. Our handheld cradles only support network connections, no usb or serial, so i have to use networking to get the data transfered. Here's the problem. I have the server accepting connections fine, but i'm a little confused how to actually send the server data, and then how the...
4
2506
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
10
2442
by: eggie5 | last post by:
Is it possible to get a file without using a form post? I want to get the data (bytes) of a file, text or binary, and just save it to a variable. Similar to the post body of a form that has a file input element in it. Ultimately what I want to do is get a file off client machine (that they specify) and send it to the server using a standard post request. This is exactly the same as a form post with an file input element, but I don't...
11
4890
by: Jeff | last post by:
Hello everyone. I've searched through the archives here, and it seems that questions similar to this one have come up in the past, but I was hoping that I could pick your Pythonic brains a bit. Here's a broad overview of what I need to do: cross-platform, client- side GUI apps that interact with a server backed by a database. I'd also like the possibility of having a web interface for small portions of the app. It will be a fairly...
0
1515
by: 85ssp | last post by:
I am creating a small server client program that is meant for up to 70 connections from 70 different computers on a network. Everything in the program functions correctly except when testing operations with a server crash, the clients go into a disconnected state and wait for the server to come back up. Once the server is up the clients attept to connect. 75% of the time all clients connect and there connect message is accepted and...
7
4691
by: Anil | last post by:
I have a Javascript program which runs in the browser and has functions work(), and stop(). It listens to commands from the server to work() and can be interrupted by the server to stop(). I am using XmlHttpRequest to talk to the server. So I use http GET to send a command "ready" to the server, which replies at some point in time by sending "work" which is invoked by the callback. As per my understanding, the browser client is single...
0
9650
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
9497
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
10363
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...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
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
5398
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...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.