Passing ArrayList from unmanaged code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GeRmIc

    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!
  • Willy Denoyette [MVP]

    #2
    Re: Passing ArrayList from unmanaged code

    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" <GeRmIc@discuss ions.microsoft. com> wrote in message
    news:0437FD84-B04C-41CD-AAA7-597CA18FBD2B@mi crosoft.com...[color=blue]
    > 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![/color]


    Comment

    • Dan  Bass

      #3
      Re: Passing ArrayList from unmanaged code


      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" <GeRmIc@discuss ions.microsoft. com> wrote in message
      news:0437FD84-B04C-41CD-AAA7-597CA18FBD2B@mi crosoft.com...[color=blue]
      > 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![/color]


      Comment

      • GeRmIc

        #4
        Re: Passing ArrayList from unmanaged code

        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!)

        Comment

        • GeRmIc

          #5
          Re: Passing ArrayList from unmanaged code

          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?

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: Passing ArrayList from unmanaged code

            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" <GeRmIc@discuss ions.microsoft. com> wrote in message
            news:F19B8428-8E42-4E41-95E6-23EE900FCB12@mi crosoft.com...[color=blue]
            > 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?[/color]


            Comment

            Working...