Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

TrIDLib - PowerBASIC sample usage

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TrIDLib - PowerBASIC sample usage

    Code:
    ' TrIDLib PowerBASIC Demo
    ' [url]http://mark0.net/code-tridlib-e.html[/url]
    
    #DIM ALL
    
    #INCLUDE "TrIDLib-Const.inc"
    #INCLUDE "TrIDLib-Funct.inc"
    
    FUNCTION PBMAIN
      LOCAL ret    AS LONG           
      LOCAL szBuf  AS ASCIIZ * 4096 
      LOCAL ResNum AS LONG           
      LOCAL ResId  AS LONG           
      LOCAL sOut$, MyFile$        
    
      MyFile$ = "triddefs.trd"               ' a random file to analyze
        
      ret = TrID_LoadDefsPack("")            ' load the definitions package (TrIDDefs.TRD) from current path
      
      ret = TrID_SubmitFileA((MyFile$))      ' submit the file
      ret = TrID_Analyze()                   ' perform the analysis
      IF ret THEN
        ResNum = TrID_GetInfo(%TRID_GET_RES_NUM, 0, szBuf)         ' get the number of results
        IF ResNum = 0 THEN
          sOut$ = "Unknown filetype!"
        ELSE
          FOR ResId = 1 TO ResNum                                    ' cycle trough the results
            Ret = TrID_GetInfo(%TRID_GET_RES_FILETYPE, ResId, szBuf) ' get filetype descriptions
            sOut$ = sOut$ & STR$(ResId)& ":" & $TAB & szBuf
            Ret = TrID_GetInfo(%TRID_GET_RES_FILEEXT, ResId, szBuf)  ' get filetype extensions
            sOut$ = sOut$ & " (" & szBuf & ")"
            Ret = TrID_GetInfo(%TRID_GET_RES_POINTS, ResId, szBuf)   ' get the matching points
            sOut$ = sOut$ & " -" & STR$(Ret)
            sOut$ = sOut$ & $CRLF
          NEXT ResId
        END IF
        msgbox sOut$
      ELSE
        msgbox "Error(s) occurred!", , "TrID_Analyze"
      END IF
      
    END FUNCTION
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

  • #2
    The two include files:

    TrIDLib-const.inc

    Code:
    '-------------------------------------------------------
    ' Constants FOR TrID_GetInfo
    '-------------------------------------------------------
    
    %TRID_GET_RES_NUM         = 1     ' Get the number of results available
    %TRID_GET_RES_FILETYPE    = 2     ' Filetype descriptions
    %TRID_GET_RES_FILEEXT     = 3     ' Filetype extension
    %TRID_GET_RES_POINTS      = 4     ' Matching points
    
    %TRID_GET_VER             = 1001  ' TrIDLib version (major * 100 + minor)
    %TRID_GET_DEFSNUM         = 1004  ' Number of filetypes definitions loaded
    
    
    '-------------------------------------------------------
    ' Additional constants for the full version
    '-------------------------------------------------------
    
    %TRID_GET_DEF_ID          = 100   ' Get the id of the filetype's definition for a given result
    %TRID_GET_DEF_FILESCANNED = 101   ' Various info about that def
    %TRID_GET_DEF_AUTHORNAME  = 102   '     "
    %TRID_GET_DEF_AUTHOREMAIL = 103   '     "
    %TRID_GET_DEF_AUTHORHOME  = 104   '     "
    %TRID_GET_DEF_FILE        = 105   '     "
    %TRID_GET_DEF_REMARK      = 106   '     "
    %TRID_GET_DEF_RELURL      = 107   '     "
    %TRID_GET_DEF_TAG         = 108   '     "
    %TRID_GET_DEF_MIMETYPE    = 109   '     "
    
    %TRID_GET_ISTEXT          = 1005  ' Check if the submitted file is text or binary one
    TrIDLib-funct.inc

    Code:
    '-------------------------------------------------------
    ' Functions
    '-------------------------------------------------------
    
    DECLARE FUNCTION TrID_LoadDefsPack LIB "tridlib.dll" ALIAS "TrID_LoadDefsPack" (BYREF szPath AS ASCIIZ) AS LONG
    DECLARE FUNCTION TrID_SubmitFileA  LIB "tridlib.dll" ALIAS "TrID_SubmitFileA"  (BYREF szFileName AS ASCIIZ) AS LONG
    DECLARE FUNCTION TrID_Analyze      LIB "tridlib.dll" ALIAS "TrID_Analyze"      () AS LONG
    DECLARE FUNCTION TrID_GetInfo      LIB "tridlib.dll" ALIAS "TrID_GetInfo"      (BYVAL lInfoType AS LONG, _
                                                                                    BYVAL lInfoIdx AS LONG, _
                                                                                    BYREF sTrIDRes AS ASCIIZ) AS LONG
    
    '-------------------------------------------------------
    ' Additional function for the full version
    '-------------------------------------------------------
    
    DECLARE FUNCTION TrID_SetDefsPack  LIB "tridlib.dll" (BYVAL lDefsPtr AS LONG) AS LONG
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

    Comment

    Working...
    X