473,657 Members | 2,504 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::_Arra yList** larray; //This is the problem???

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

Give error C2664: 'IManagedInterf ace::getVal' : cannot convert parameter 3
from 'mscorlib::_Arr ayList ***__w64 ' to 'mscorlib::_Arr ayList ** '

How do i work around this??

Thanks ppl!
Nov 16 '05 #1
5 7202
I'm not clear on where you get "mscorlib::_Arr ayList" 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****@discuss ions.microsoft. com> wrote in message
news:04******** *************** ***********@mic rosoft.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::_Arra yList** larray; //This is the problem???

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

Give error C2664: 'IManagedInterf ace::getVal' : cannot convert parameter 3
from 'mscorlib::_Arr ayList ***__w64 ' to 'mscorlib::_Arr ayList ** '

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****@discuss ions.microsoft. com> wrote in message
news:04******** *************** ***********@mic rosoft.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::_Arra yList** larray; //This is the problem???

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

Give error C2664: 'IManagedInterf ace::getVal' : cannot convert parameter 3
from 'mscorlib::_Arr ayList ***__w64 ' to 'mscorlib::_Arr ayList ** '

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(structur es) 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****@discuss ions.microsoft. com> wrote in message
news:F1******** *************** ***********@mic rosoft.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
3527
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 this method and have it set the instance to hold the right data. >From what I've read it seems I should be able to pass C# objects to managed C++ methods and it should just work; however, when I try it, my C# instance comes out null. If I step...
16
1878
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 would be declared in the body of the Main() and not inside the using (even not referenced in the using) ? Would be there something to call to dispose them ?
2
4672
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 this method and have it set the instance to hold the right data. >From what I've read it seems I should be able to pass C# objects to managed C++ methods and it should just work; however, when I try it, my C# instance comes out null. If I step...
17
3672
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 reading
5
14160
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 anyone point me to a resource that can tell me how to do this? Thanks in advance
12
11363
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), I am calling a managed C# method(I use gcnew to instantiate the managed class). One of the parameters of this C# method is a delegate. I need to pass the none static member function as a delegate(function pointer) as a parameter in the managed C#...
94
5656
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. Thanks.
17
7239
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?
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
8392
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2726
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
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.