473,516 Members | 2,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing managed arrays

Does anyone know how to pass a managed array to a method and have that
method actually create the array if necessary, ie., if the passed array is
null? For example:

void AddAttribute(XmlAttribute* attribList[], XmlAttribute* anAttrib)
{
if (attribList == 0L) {
attribList = new XmlAttribute * [1];
attribList[0] = anAttrib;
} else {
if (!AttributeExists(attribList, anAttrib)) {
int size = attribList->get_Length();
for (int i=1; i<=size; i++) {
if (attribList[i-1] == 0L) {
attribList[i-1] = anAttrib;
goto Done;
}
}

XmlAttribute* temp[];
temp = new XmlAttribute * [size+1];
attribList->CopyTo(temp, 0);
temp[size] = anAttrib;
attribList = temp;
} else {
throw new ApplicationException("Attribute already exsits");
}
}
Done: ;
}

In the old days of native C++, I would have passed the array as:
XmlAttribute*& attribList so that the function can change the pointer
itself. Thanks. Jon.
Nov 16 '05 #1
6 1576
Hi,
Does anyone know how to pass a managed array to a method and have that
method actually create the array if necessary, ie., if the passed array is
null? For example:
void AddAttribute(XmlAttribute* attribList[], XmlAttribute* anAttrib)
{

Does the following help?

void AddAttribute(XmlAttribute* (*attribList)[], XmlAttribute* anAttrib)

...
Regards,
Vadim.


Nov 16 '05 #2
It doesn't like when I do:

attribList = new XmlAttribute * [1];

Jon.
"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:u6**************@TK2MSFTNGP11.phx.gbl...
Hi,
Does anyone know how to pass a managed array to a method and have that
method actually create the array if necessary, ie., if the passed array is null? For example:
void AddAttribute(XmlAttribute* attribList[], XmlAttribute* anAttrib)
{

Does the following help?

void AddAttribute(XmlAttribute* (*attribList)[], XmlAttribute* anAttrib)

..
Regards,
Vadim.

Nov 16 '05 #3
Hi,
It doesn't like when I do:

attribList = new XmlAttribute * [1];


The following should work:

void AddAttribute2(XmlAttribute* (*attribList)[], XmlAttribute* anAttrib)
{
*attribList = new XmlAttribute *[2];
....
}

...
Regards,
Vadim.
Nov 16 '05 #4
Jon,

Sure it won't compile, attribList is pointer to array of XmlAttribute*, so
you need dereference it before:

(*attribList)[0] = anAttrib;
"jlea" <jo*@leapsoft.com> wrote in message
news:Oa*************@tk2msftngp13.phx.gbl...
Your modified line compiled by the next line didn't:

attribList[0] = anAttrib;

it says

DAL_XML.cpp(377) : error C2440: '=' : cannot convert from
'System::Xml::XmlAttribute __gc *' to 'System::Xml::XmlAttribute __gc *
__gc[]'

Jon.
"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Hi,
It doesn't like when I do:

attribList = new XmlAttribute * [1];


The following should work:

void AddAttribute2(XmlAttribute* (*attribList)[], XmlAttribute* anAttrib) {
*attribList = new XmlAttribute *[2];
...
}

..
Regards,
Vadim.


Nov 16 '05 #5
I got the function to compile - thanks, but now I'm having problems with
passing it the actual array. I'm using the following code:

public System.Xml.XmlAttribute[] AnyAttr;
//the data member is in a C# class

XmlAttribute* attribList[] = pSSConnItemType->AnyAttr; //get the
array from the C# object
AddAttribute(attribList, anAttrib);
//doesn't compile
error C2664: 'void
LeapSoft::DAL_Imp::DAL_XML::AddAttribute(System::X ml::XmlAttribute __gc
*(__gc *) __gc[],System::Xml::XmlAttribute __gc *)' : cannot convert
parameter 1 from 'System::Xml::XmlAttribute __gc * __gc[]' to
'System::Xml::XmlAttribute __gc *(__gc *) __gc[]'
Can only convert a __gc array to or from Object * or Array *

Jon.

"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:#w**************@TK2MSFTNGP12.phx.gbl...
Jon,

Sure it won't compile, attribList is pointer to array of XmlAttribute*, so
you need dereference it before:

(*attribList)[0] = anAttrib;
"jlea" <jo*@leapsoft.com> wrote in message
news:Oa*************@tk2msftngp13.phx.gbl...
Your modified line compiled by the next line didn't:

attribList[0] = anAttrib;

it says

DAL_XML.cpp(377) : error C2440: '=' : cannot convert from
'System::Xml::XmlAttribute __gc *' to 'System::Xml::XmlAttribute __gc *
__gc[]'

Jon.
"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Hi,

> It doesn't like when I do:
>
> attribList = new XmlAttribute * [1];
>

The following should work:

void AddAttribute2(XmlAttribute* (*attribList)[], XmlAttribute* anAttrib) {
*attribList = new XmlAttribute *[2];
...
}

..
Regards,
Vadim.



Nov 16 '05 #6
Hi Jon,

Add & before attribList:

AddAttribute(&attribList, anAttrib);

P.S.: Probably it does make sense obtain good book about C++ language...
"jlea" <jo*@leapsoft.com> wrote in message
news:uG**************@tk2msftngp13.phx.gbl...
I got the function to compile - thanks, but now I'm having problems with
passing it the actual array. I'm using the following code:

public System.Xml.XmlAttribute[] AnyAttr;
//the data member is in a C# class

XmlAttribute* attribList[] = pSSConnItemType->AnyAttr; //get the
array from the C# object
AddAttribute(attribList, anAttrib);
//doesn't compile
error C2664: 'void
LeapSoft::DAL_Imp::DAL_XML::AddAttribute(System::X ml::XmlAttribute __gc
*(__gc *) __gc[],System::Xml::XmlAttribute __gc *)' : cannot convert
parameter 1 from 'System::Xml::XmlAttribute __gc * __gc[]' to
'System::Xml::XmlAttribute __gc *(__gc *) __gc[]'
Can only convert a __gc array to or from Object * or Array *

Jon.

"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:#w**************@TK2MSFTNGP12.phx.gbl...
Jon,

Sure it won't compile, attribList is pointer to array of XmlAttribute*, so you need dereference it before:

(*attribList)[0] = anAttrib;
"jlea" <jo*@leapsoft.com> wrote in message
news:Oa*************@tk2msftngp13.phx.gbl...
Your modified line compiled by the next line didn't:

attribList[0] = anAttrib;

it says

DAL_XML.cpp(377) : error C2440: '=' : cannot convert from
'System::Xml::XmlAttribute __gc *' to 'System::Xml::XmlAttribute __gc * __gc[]'

Jon.
"Vadim Melnik" <vm****@REMOVETHISdocsultant.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
> Hi,
>
> > It doesn't like when I do:
> >
> > attribList = new XmlAttribute * [1];
> >
>
> The following should work:
>
> void AddAttribute2(XmlAttribute* (*attribList)[], XmlAttribute*

anAttrib)
> {
> *attribList = new XmlAttribute *[2];
> ...
> }
>
> ..
> Regards,
> Vadim.
>
>



Nov 16 '05 #7

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

Similar topics

58
10052
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
5
7197
by: GeRmIc | last post by:
Hi, I am doing an interop from unmanaged code to C#. How do i pass an ArrayList pointer from an unmanaged code, (structres are easily passed by between C# and C). //This is the C code NameStruct lnames; //This is a structure in C#
3
1455
by: Germic | last post by:
Hi, I want to create an Hashtable in C# and pass an pointer to the hashtable to a C code. Later, the C code could reference the hashtable by passing the pointer to the hashtable as a ref parameter. what is the correct way to do this? Thanks,
1
3428
by: Kurt Richardson | last post by:
Hi all Sorry to bother you with what is probably a really trivial question for you C++ experts. My programming skill are pretty amateur, but I'm pretty good at VB.NET. However, I'm wanting to realise some of the speed benefits of writing some of my routines in C++ and accessing them from my VB software. I have managed to do this with a...
6
2535
by: Omid Hodjati | last post by:
Hi All, I implemented an encryption algorithm using C#, native C++ and managed C++. Then I measured the CPU time used for executing this algorithm in all implementation. The managed version of C++ was the worst ! It is 20 times slower that the native version and 6 times slower that the C# versio !! Because i wanted to use automatic memory...
1
1509
by: Steve Baer | last post by:
I'm wrapping some unmanaged C++ classes with managed versions for use in the ..NET world. Everything is going great except I can't figure out a good method for passing simple data type arrays into unmanaged classes. Say I have a function void UnManagedClass::FillOutArray(int size, int* data); where data is an array of unmanaged ints and...
3
3773
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes a variant containing an array, and interop expects a parameter of type object if you are passing a variant (you are expected to cast it to the...
17
3659
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to compile i get the following error: Attempted to read or write protected memory the C function should not be manipulating the input arra, only...
17
7212
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
6
3875
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper for a C++ DLL file, but am having problems with passing strings as parameters. How should I be writing my C# function call when the C header file is definined as taking a char * as an argument? For example the C++ header says SDCERR GetCurrentConfig(DWORD *num, char *name); I am using Uint for the *num...
0
7276
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...
0
7182
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...
1
7142
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...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4773
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...
0
3267
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...
0
1624
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
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
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...

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.