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 / .NET Framework / Interop / October 2003

Tip: Looking for answers? Try searching our database.

Passing ArrayList between unmanaged and managed code C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marek A. Dabek - 22 Oct 2003 12:00 GMT
Hi!
I'm not sure if and how it could be done, I've read many docs from
msdn and now i'm pretty pessimistic about it. Anyway, i have a
unmanaged C++ code that reads some files and loads an
System::Collection::ArrayList:
Here's unmanaged code that loads an ArrayList
[...]
while(dane->kol!=NULL)
{
    for(int i=0;i<dane->liczpol;i++)
    {
    char typ = (char)dane->tabtyp[i];
    if(typ=='1')
    {
          int* temp_int = (int*)dane->kol->buf;
     pole_kolejki->Add(__box(*temp_int));
        [...]
    else if(typ=='C'|| typ== 'c')
     {
      String* temp_str = new           String(dane->kol->buf);
      pole_kolejki->Add(temp_str);
     }
    }
    kolejka->Add(pole_kolejki);
    dane->kol=dane->kol->nast;
}
[...]

Then i have a function that returns an ArrayList (Kolejka_class is
class that provides the above functionality) :

__declspec(dllexport) /*Object __gc**/System::Collections::ArrayList*
__stdcall Kolejka_numery_kontrah(){

Kolejka_class* numery_kontrah_kol = new
Kolejka_class(&numery_kontrah);

return (static_cast<System::Collections::ArrayList*>(numery_kontrah_kol->pobierz_kolejke()));
}

Finally I have it in dll and want to call from managed C++ code:

public __value struct KolejkaDLL
{
  [DllImport("Kolejki.dll")]
  /*No idea how to marshal returning type */
  static public System::Collections::ArrayList*
Kolejka_numery_kontrah();
};
[...]
System::Collections::ArrayList*
KolejkiNET::Kolejka_wrapp::pobierz_Numery_Kontrah()
{
    lista=KolejkaDLL::Kolejka_numery_kontrah(); /*HERE I GET AN
EXCEPTION:
Can not marshal return value: The type definition of this type has no
layout information.*/
    return lista;   
}
Mattias Sj?gren - 22 Oct 2003 22:19 GMT
Marek,

>Anyway, i have a
>unmanaged C++ code that reads some files and loads an
>System::Collection::ArrayList:
>Here's unmanaged code that loads an ArrayList

The code you posted looks like managed C++ to me. You are, after all,
using the __box keyword and various managed types.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Marek A. Dabek - 23 Oct 2003 11:53 GMT
Thanx for answer, however, this part with Arraylist is managed, but
it's mixed with a lot of unmanaged code, and output is win32.
What is more, i can't use this dll in j# or c++ .net project because
i'm getting the exception i was writting about ("Can not marshal
return value: The type definition of this type has no layout
information."). So my question is, how to use this ArrayList from dll
in j# or in C++ .net project.

Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote in message news:<#6tk0IOmDHA.3312@tk2msftngp13.phx.gbl>...
> Marek,
>
[quoted text clipped - 7 lines]
>
> Mattias

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.