Passing ArrayList from unmanaged code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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.
 
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.
 
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!)
 
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?
 
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.
 
Back
Top