469,626 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

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 7028
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Cybertof | last post: by
17 posts views Thread by mr.resistor | last post: by
5 posts views Thread by res7cxbi | last post: by
94 posts views Thread by Peter Olcott | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
3 posts views Thread by Saad | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.