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
Jochen Kalmbach [MVP] - 16 Oct 2005 17:00 GMT
Hi Peter!
> struct TRANSFER {
> BYTE data;
[quoted text clipped - 13 lines]
> 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));
}

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/