By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,914 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,914 IT Pros & Developers. It's quick & easy.

Passing ArrayList from unmanaged code

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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.