473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ArrayList interop

Hi,

I've got the following problem: I need to create a special Dll that is based
on MFC, but also includes also managed code (which works fine and isn't a
problem). The problem occurrs in the following:

struct TRANSFER {
BYTE data;
__int64 hits;
};

void MyTestFunc(ArrayList* list)
{
TRANSFER a;
a.data = 12; //just some test data
a.hits = 13;
list->Add(a); //compiler error
}

Now, when I try to compile this I receive the following error:

C:\Interface.cpp(24): error C2664: 'System::Collections::ArrayList::Add' :
cannot convert parameter 1 from 'TRANSFER' to 'System::Object __gc *'

But how can I marshal this correctly? Any ideas?

Thanks,

Peter
Nov 17 '05 #1
1 1712
Hi Peter!
struct TRANSFER {
BYTE data;
__int64 hits;
};

void MyTestFunc(ArrayList* list)
{
TRANSFER a;
a.data = 12; //just some test data
a.hits = 13;
list->Add(a); //compiler error
}

Now, when I try to compile this I receive the following error:

C:\Interface.cpp(24): error C2664: 'System::Collections::ArrayList::Add' :
cannot convert parameter 1 from 'TRANSFER' to 'System::Object __gc *'


What do you want to store in the ArrayList? Only managed data can be
stored in the ArrayList, so you need to declare a managed-type for your
structure:

public __value struct Transfer
{
System::Byte data;
System::Int64 hits;
};

void MyTestFunc(ArrayList* list)
{
TRANSFER a;
a.data = 12; //just some test data
a.hits = 13;

// marshal the data to the managed struct:
Transfer t;
t.data = a.data;
t.hits = a.hits;
al->Add(__box(t));
}

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2

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

Similar topics

0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
4
by: TJO | last post by:
I am looking for an approach that would allow me to transform an ArrayList of ArrayLists into a byte and vise versa. Each item in the ArrayList is an ArrayList of Point objects which represent...
5
by: GeRmIc | last post by:
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 ...
1
by: GeRmIc | last post by:
Hi, How do i pass an ArrayList from C# to C? I am accessing a fn in C# which takes an ref ArrayList as a parameter, how do i pass this datastruct from C? Thanks! (i know i will post in the...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
2
by: Jayme Pechan | last post by:
I migrated a formerly C++ COM component to C# and I have been able to duplicate all the old behavior except for one. I have an enumeration property that returns a list of com objects. Using the...
8
by: | last post by:
I have a simple structure for example purposes I add to an array list public structure MyStruct dim counter as integer end structure dim mylist as ArrayList dim x as New MyStruct ...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
12
by: Justin | last post by:
Ok, I give up. I can't seem to construct a decent (productive) way of sorting my arraylist. I have a structure of two elements: Structure TabStructure Dim TabName As String Dim FullFilePath...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.