473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing ArrayList from unmanaged code

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#
GermStruct lgerms; //This is a structure in C#
mscorlib::_ArrayList** larray; //This is the problem???

//I am calling it like
str = cpi->getVal(&lnames,&lgerms,&larray);

Give error C2664: 'IManagedInterface::getVal' : cannot convert parameter 3
from 'mscorlib::_ArrayList ***__w64 ' to 'mscorlib::_ArrayList ** '

How do i work around this??

Thanks ppl!
Nov 16 '05 #1
5 7195
I'm not clear on where you get "mscorlib::_ArrayList" from nor what you are
trying here, all I can say ArrayList is a managed class so you can't use it
in unmanaged C++.
Please post a simple but complete sample that illustrates the problem.

Willy.
PS. Better post such questions to the interop NG.

"GeRmIc" <Ge****@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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#
GermStruct lgerms; //This is a structure in C#
mscorlib::_ArrayList** larray; //This is the problem???

//I am calling it like
str = cpi->getVal(&lnames,&lgerms,&larray);

Give error C2664: 'IManagedInterface::getVal' : cannot convert parameter 3
from 'mscorlib::_ArrayList ***__w64 ' to 'mscorlib::_ArrayList ** '

How do i work around this??

Thanks ppl!

Nov 16 '05 #2

If I were you I'd pass back fixed arrays ( eg. Int[100] ) from the unmanaged
code, then cast them into ArrayList when they hit the managed code.
"GeRmIc" <Ge****@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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#
GermStruct lgerms; //This is a structure in C#
mscorlib::_ArrayList** larray; //This is the problem???

//I am calling it like
str = cpi->getVal(&lnames,&lgerms,&larray);

Give error C2664: 'IManagedInterface::getVal' : cannot convert parameter 3
from 'mscorlib::_ArrayList ***__w64 ' to 'mscorlib::_ArrayList ** '

How do i work around this??

Thanks ppl!

Nov 16 '05 #3
Hi,

Sorry if i wasn't clear earlier.

All i am trying to do is my C code accesses a webservice through a C# library.
In my first hit to the C# code, it accesse the webservice which returns an
array of array.

My C code can consume only 1 array (Structure) at one time so the subsequent
hits to the C# library should pass the subsequent arrays(structures) to the C
code without having to access the webservice everytime.

So I want to store the returned values from the webservice in an ArrayList
or Hashtable and pass the address as a parameter when every i call the C#
library.

Or is there anyother way?

Thanks,
(will start posting such ques in the interop NG...Noted!)
Nov 16 '05 #4
Hi Dan,

My problem is that, the managed code holds an arraylist which obviously
contains fixed structures or arrays. When ever the unmanaged code calls the
managed code, it should return the top most value from the array list.

How should i go about this?
Nov 16 '05 #5
You can't pass a raw pointer to an object in the managed heap to unmanaged
code and access the object from unmanaged code, argument types other than
blitable must be marshaled.
It's still not clear to me what kind of interop you are using here, native
C/C++ COM interop using tlbimport or managed C++/C# using C++ interop.
If you are using COM interop you can pass the managed array as a SAFEARRAY.

Willy.
"GeRmIc" <Ge****@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
Hi Dan,

My problem is that, the managed code holds an arraylist which obviously
contains fixed structures or arrays. When ever the unmanaged code calls
the
managed code, it should return the top most value from the array list.

How should i go about this?

Nov 16 '05 #6

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

Similar topics

1
3497
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
16
1858
by: Cybertof | last post by:
Hi ! I'm wondering about the use of the 'using' statement. In a procedure, should i declare all instance variables in a using clause ? In the below code, what would happen if MyFont & MyFont2...
2
4667
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
17
3658
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...
5
14151
by: res7cxbi | last post by:
I like to implement and ArrayList like Java's and C# in C++ but I have no clue how to start I really don't want to use Managed C++ and use ArrayList that way - I want to keep it "unmanaged" Can...
12
11338
by: Haxan | last post by:
Hi, I have my main application class(unmanaged) that has a none static member function that I need to pass as a delegate to managed C# method. In one of the methods of this class(unmamanged),...
94
5578
by: Peter Olcott | last post by:
How can I create an ArrayList in the older version of .NET that does not require the expensive Boxing and UnBoxing operations? In my case it will be an ArrayList of structures of ordinal types. ...
17
7211
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...
3
397
by: Saad | last post by:
Hi, I have a struct as follows: public __gc struct STTemp { public: int someint; System::Collections::ArrayList* arrTemp;
0
7199
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,...
0
7076
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...
0
7274
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,...
0
7323
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...
1
5005
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...
0
3162
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...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
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 ...
0
377
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...

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.