Re: Indexing of IntPtr

From: Tamir Khason (tamir-NOSPAM_at_tcon-NOSPAM.co.il)
Date: 09/20/04


Date: Mon, 20 Sep 2004 10:20:37 +0200

Almost, it's going like this:

[DllImport("Foo.dll")]
  static extern IntPtr int_unmg_get_items(IntPtr raw);

                public IntPtr Items {
                 get {
                  IntPtr ret = int_unmg_get_items (Handle);
                  return ret;
                 }
                }

-- 
        Tamir Khason
 You want dot.NET? Just ask:
 "Please, www.dotnet.us "
"Richard Blewett [DevelopMentor]" <richardb@develop.com> wrote in message 
news:uvVMsxmnEHA.2764@TK2MSFTNGP11.phx.gbl...
> OK, so an interop call returns a pointer to an array which you receive as 
> an IntPtr, e.g.:
>
> [DllImport("Foo.dll")]
>
> IntPtr GetArray();
>
> or something like that.
>
> Now in the class you have you want to provide access to this array via an 
> indexer. However
>
> IntPtr i = GetArray();
>
> public char this[int index]
>
> {
>
>     get
>
>     {
>
>         return i[index];
>
>     }
>
> }
>
> doesn't compile?
>
> IntPtr is not mea';t to be manipulated from managed code only received and 
> returned - as I explained. You need to receive this array back in a way in 
> which you can manipulate not as an IntPtr.
>
> Have I got the scenario right? and if so can you show us the P/Invoke 
> signature (DllImport, etc)
>
> regards
>
> Richard Blewett - DevelopMentor
>
> http://staff.develop.com/richardb/weblog
>
>
>
> 
> nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/>
>
> As I mentioned earlier I build a function with return from unmanaged the
> pointer to array item on override of "this" method so when using Func[1] 
> it
> will return the pointer to 1st member of source array, but (see message) 
> an
> error on calling this function
>
>
>
> "Richard Blewett [DevelopMentor]" <richardb@develop.com> wrote in message
> news:OXMPlMmnEHA.3464@tk2msftngp13.phx.gbl...
> >I think you misunderstand the nature of IntPtr. It is mean't to be used 
> >to
> >represent an opaque handle retrieved via interop - its not a pointer to 
> >an
> >integer or a pointer of integer size. The point is its a "thing" that you
> >receive from and pass back to the interop layer (and so to the operating
> >system or some other DLL). if you want to walk a specific array just 
> >index
> >into the array or use foreach.
> >
> > What exactly are you trying to achieve?
> >
> > Regards
> >
> > Richard Blewett - DevelopMentor
> >
> > http://staff.develop.com/richardb/weblog
> >
> >
> > nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/#G7Bt8lnEHA.2764@TK2MSFTNGP11.phx.gbl
>
> > I have a pointer to array and I want to apply indexing to this Array so 
> > I
> > have function (name it IntPrt Func[]) to go to certain member I can use
> > (as
> > C++) Func[5], but in C# I recieve an error "Cannot apply indexing with 
> > []
> > to
> > an expression of type 'System.IntPtr'".
> >
> > How to get rid of it?
> >
> > TNX
> >
> > --
> > Tamir Khason
> > You want dot.NET? Just ask:
> > "Please, www.dotnet.us "
> >
> >
> >
> > ---
> > Incoming mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
> >
> >
> >
> > [microsoft.public.dotnet.languages.csharp]
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
>
>
>
> [microsoft.public.dotnet.languages.csharp] 


Relevant Pages

  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)
  • Re: Array of pointer in C#
    ... what you have is not an array, ... pointer that's marshalled as IntPtr. ... TBufferHeader* as a IntPtr as well. ... "Kathy Tran" wrote: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: why cannot assign to function call
    ... hypothetical C-like languages, ... sizeof business would still indicate that a pointer was being passed. ... talk about variables of an array type. ... the earlier version of the standard didn't have numbered ...
    (comp.lang.python)
  • Re: multi dimensional arrays as one dimension array
    ... please - where does the standard say that such a conversion ... Pointer conversion yields a pointer to the same object as ... exist only where there are array declarations. ...
    (comp.lang.c)
  • Re: Allocatable components + mixed-language
    ... passed from C and the array reconstructed in Fortran using the C Interop ... Declare a local POINTER to an array of floats. ... Our central Fortran routine is called quite often. ...
    (comp.lang.fortran)