New topic: 

Pointers and structures

<http://forums.realsoftware.com/viewtopic.php?t=46542>

         Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic          Author  
Message        eliott          Post subject: Pointers and structuresPosted: Sun 
Jan 13, 2013 9:44 am                         
Joined: Sun Oct 17, 2010 9:46 am
Posts: 71
Location: Berlin, Germany                Is there a possibility to dereference 
a RB pointer pointing to a RB structure?   
                             Top                MonkeybreadSoftware          
Post subject: Re: Pointers and structuresPosted: Sun Jan 13, 2013 10:12 am      
                           
Joined: Wed May 10, 2006 2:42 pm
Posts: 2840
Location: Germany                Please read Documentation about Ptr data type.

Greetings
Christian      
_________________
See you in Orlando, Florida for Real World 2012
More details and registration here:
http://www.realsoftware.com/community/realworld.php  
                             Top                eliott          Post subject: 
Re: Pointers and structuresPosted: Sun Jan 13, 2013 11:10 am                    
     
Joined: Sun Oct 17, 2010 9:46 am
Posts: 71
Location: Berlin, Germany                The Ptr docs don't mention structures, 
I know. But autocompletion shows accessors for all my self-defined structures 
on each Ptr variable.

Ptr.NSRect( offset As Integer = 0 ) As NSRect
Ptr.NSPoint( offset As Integer = 0 ) As NSPoint
Ptr.CFRange( offset As Integer = 0 ) As CFRange
etc.

I also found a related discussion on your listarchive-realbasic-nug dating back 
to 2006, where somebody was asking something similar:
Quote:> Also - how can I convert a pointer to a structure obtained from a Dylib 
call into an RB structure reference ? 

You can't do that directly, but you can dereference the pointer: 

Dim foo As Ptr, bar As someStructure 
bar = foo.someStructure 

Mars Saxman 
REAL Software
   
                             Top                npalardy          Post subject: 
Re: Pointers and structuresPosted: Sun Jan 13, 2013 11:51 am                    
   Real Software Engineer          
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7674
Location: Canada, Alberta, Near Red Deer                eliott wrote:Is there a 
possibility to dereference a RB pointer pointing to a RB structure?

Why would you need a ptr ?      
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                             Top                eliott          Post subject: 
Re: Pointers and structuresPosted: Sun Jan 13, 2013 12:04 pm                    
     
Joined: Sun Oct 17, 2010 9:46 am
Posts: 71
Location: Berlin, Germany                It's an external library (no source 
available). This library has two functions, one returns a pointer to a C struct 
(not a C struct), the other the kind of the struct (as C string). You call the 
latter to know what kind of struct the first is giving you.
This would enable me to then do the following (where kindOfStruct and p are the 
result of the calls to the two functions):
Select Case kindOfStruct
Case "structA"
  Dim s As StructA
  s = p.StructA
Case "structB"
  Dim s As StructB
  s = p.StructB
  ...
   
                             Top                doofus          Post subject: 
Re: Pointers and structuresPosted: Sun Jan 13, 2013 12:13 pm                    
             
Joined: Thu Sep 10, 2009 2:50 am
Posts: 335
Location: Santa Cruz, CA, USA                does this help make sense?
dim p As Ptr 'create pointer

callOSFunction(p) 'set pointer to some address

//if pointer is only to struct
dim rect1 As NSRect = p.NSRect 'implicit 0 offset

//if struct is 16 bytes in
dim rect2 As NSRect = p.NSRect(16)


Your select case looks like it'd work, maybe there's an offset needed. Also, I 
think you can pass in a struct directly, in place of a pointer.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to