Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2005

Tip: Looking for answers? Try searching our database.

ArrayList interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Schmitz - 16 Oct 2005 11:49 GMT
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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.