Results 1 to 7 of 7

Thread: Using TrIDLib from thinBasic

  1. #1

    Using TrIDLib from thinBasic

    Here's a small demo that show how to use TrIDLib free edition from thinBasic.
    TrIDLib is a DLL that make implementing the same filetype recognition abilities of TrID on another app / tool a quick & easy task.

    The usage of this edition of the library is free for personal, non commercial, reasearch or educational use.

    The TrIDLib's web page is still being completed, as well as the documentation, but I think the sample source will be enough to get anyone interested up & running.

    Bye!

    ' TrIDLib thinBasic Demo
    ' http://mark0.net/code-tridlib-e.html
    
    uses "console"
    
    #INCLUDE "TrIDLib-Const.inc"
    #INCLUDE "TrIDLib-Funct.inc"
    
    LOCAL ret   AS LONG      
    LOCAL szBuf  AS ASCIIZ * 4096 
    LOCAL ResNum AS LONG      
    LOCAL ResId  AS LONG      
    LOCAL sOut$  as string
    local MyFile$ as string
    
    MyFile$ = "triddefs.trd"      ' a random file to analyze
    
    console_writeline "TrIDLib demo"
    console_writeline
     
    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
      console_writeline "Unknown filetype!"
     ELSE
      FOR ResId = 1 TO ResNum                  ' cycle trough the results
       Ret = TrID_GetInfo(%TRID_GET_RES_FILETYPE, ResId, szBuf) ' get filetype descriptions
       console_write STR$(ResId)& ":" & $TAB & szBuf
       Ret = TrID_GetInfo(%TRID_GET_RES_FILEEXT, ResId, szBuf) ' get filetype extensions
       console_write " (" & szBuf & ")"
       Ret = TrID_GetInfo(%TRID_GET_RES_POINTS, ResId, szBuf)  ' get the matching points
       console_writeline " -" & STR$(Ret)
      NEXT 
     END IF
    ELSE
     console_writeline "Error(s) occurred!"
    END IF
    
    console_writeline "Press any key."
    CONSOLE_WAITKEY
    
    Here's the output (the file analyzed is TrID's defs package):
    TrIDLib demo
    
    File: triddefs.trd
     1:   TrID defs package (TRD) - 22009
     2:   AOS File Format (AOS) - 10000
     3:   Generic RIFF container () - 4000
    Press any key.
    
    Bye!

  2. #2

    Re: Using TrIDLib from thinBasic

    Here are the two include files too:

    TrIDLib-const.inc
    '-------------------------------------------------------
    ' 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:
    '-------------------------------------------------------
    ' 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
    
    P.S.
    Amazing how quick & effortless the sample porting process from PowerBASIC was. The sources are about identical, except from printing on the console! Thanks to the thinBasic team for such an awesome tool!

    Bye!

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,792
    Rep Power
    10

    Re: Using TrIDLib from thinBasic

    Ciao Marco.

    Thanks a lot for this big present and for taking thinBasic into account for your TrIDLib development.

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,792
    Rep Power
    10

    Re: Using TrIDLib from thinBasic

    Marco,

    where can I get TrIDDefs.TRD file?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: Using TrIDLib from thinBasic

    Hi Mark0,

    worked well in my test for new PowerPoint fileformat, BMPs and M15.
    What surprised me was that it recognized even Fujifilm RAF, the database of supported formats is really huge


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7

    Re: Using TrIDLib from thinBasic

    Thanks Petr!

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •