GetResourcePtr
Address = GetResourcePtr(Index)
 
Parameters:

    Index = The Index of the resource in the internal resource buffer
Returns:

    Address = Address the resource, zero if doesn't exist
 

     The GetResourcePtr function returns the pointer (address in memory) of a file that's been bound to the program executable at compile time using the #AddResource directive. To query the resource the we give the GetResourcePtr function the index of the resource in the internal resource buffer array. You can locate a bound resource by using FindResourceIndex and it's filename.

      GetResourcePtr is useful as it allows a program to read and manipulate the data directly from the memory rather than disc ( ie. decompression, decryption etc). So the bound resource is hidden from the users of your program, meaning you don't need to include the file externally with the final game/application.


FACTS:


      * GetResourcePtr will return 0 if the resource doesn't exist.

      * Resources can be used as an alternative way to store information than DATA statements.

      * For more information about resource binding see the #AddResource directive.


 
Example Source: Download This Example
  // Attach this file from the common media folder in the help
  // files, which is located two folders down from where this
  // example is stored.
  #AddResource "..\..\Media/Hello-World.txt"
  
  // Search for a bound resource using the same file name
  Index=findresourceindex("..\..\Media/Hello-World.txt")
  
  // If the resource was found it's index will be 0 or higher
  If Index>-1
     
     // Display information about this resource
     Print "Resource Found"
     
     Address     =getresourceptr(Index)
     Size          =getresourcesize(Index)
     
     Print "Address In Memory:"+Str$(Address)
     Print "Size:"+Str$(Size)+" bytes"
     
     // Since we know this is a text resource
     // next we'll read these bytes into a string
     // using peekstring
     s$=PeekString(Address,Size)
     
     // Now we'll split this string into an array to display it
     Dim Rows$(0)
     
     // remove any ASC chr 13 from the string
     s$=Replace$(s$,Chr$(13),"")
     
     // split the string on the ASC II chr 10
     RowCount=SplitToArray(s$,Chr$(10),Rows$())
     
     // Display the rows of this text file
     For lp =0 To RowCount-1
        Print Rows$(lp)
     Next
     
  EndIf
  
  
  // DIsplay the number of bound resources in memory
  Print "Number OF Resources #"+Str$(getresourcequantity())
  
  Sync
  WaitKey
  
  
  
  
  
 
Related Info: #AddResource | Data | FindResourceIndex | GetResourceSize | PeekByte | PeekInt :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com