New topic: 

Deref a pointer to an array of handles in external function?

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

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        rdm          Post subject: Deref a pointer to an array of 
handles in external function?Posted: Mon May 14, 2012 6:09 pm                   
      
Joined: Mon Oct 26, 2009 10:53 pm
Posts: 5                I have a problem interfacing to an external library 
with a routine that returns a pointer to an array of handles and a pointer to 
an integer.

This is how the external routine is described in the manual as a C routine:

  Integer GetList (itemHandle ∗∗handlelist, integer ∗count)

I attempted to interface to this function using the following REALstudio code:

myGetList (ByRef mylist() As Integer, ByRef n As Integer

  Dim ItemBlock As New MemoryBlock( 32 )  'leave room for 8 handles
  Dim errcode As Integer

  Declare Function GetList Lib i1Lib ( itemList As Ptr, ByRef nitems As Integer 
) As Integer
  
  errcode = GetList( ItemBlock, n )
  If alError = 0 Then
  For i=0 To n-1
  myList( i ) = DeviceBlock.UInt32Value( i * 4 )
  Next i
  End if

  Return errcode
  
The variable n comes back with 2, the correct number of items, but the 
ItemBlock has only the first 4 bytes filled, which I believe is the pointer to 
the handle array.

So how do I declare and call the function to get the handles in the itemList 
array assigned properly into the myList array?   
                             Top                timhare          Post subject: 
Re: Deref a pointer to an array of handles in external functPosted: Mon May 14, 
2012 6:40 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11298
Location: Portland, OR  USA                Try using

ByRef itemList as Ptr

Passing a memoryblock to itemList as Ptr is the same as

itemHandle *handlelist

ByRef should get it to **handlelist

If that doesn't work (doesn't compile) then use a 4-byte memoryblock to point 
to the itemList memoryblock and pass that as Ptr.   
                             Top                rdm          Post subject: Re: 
Deref a pointer to an array of handles in external functPosted: Mon May 14, 
2012 7:30 pm                         
Joined: Mon Oct 26, 2009 10:53 pm
Posts: 5                Using ByRef itemList as Ptr does not compile, the 
compiler states that the argument itemBlock is incompatible with the function 
declaration.

Also, I do not want the pointer to the array of handles, I need the array 
itself so I can pass individual handles to other routines.

Any other ideas?   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 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