topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday March 18, 2024, 10:47 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Tiny 'Touch' 32 bits program in C (3 kb)  (Read 20066 times)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: Tiny 'Touch' 32 bits program in C (3 kb)
« Reply #25 on: October 01, 2006, 02:23 PM »
Just for fun, here's a 1kb C (well, C++) version, that has proper system return code :)


Nice!
Here's a good link btw : http://smallcode.web...optimization-tricks/
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: Tiny 'Touch' 32 bits program in C (3 kb)
« Reply #26 on: October 01, 2006, 03:17 PM »
Hello,

Here is the ported version to FBSL v3 :
One cas easily compare the C version vs the FBSL one and have a look at slight difference of both languages :)
Compiled as 'tiny' Fbsl executable, it's final weight is around 8Kb.
Code: Text [Select]
  1. // ********************************
  2. // Author : Gerome GUILLEMIN
  3. // Coded in FBSL v3
  4. // Date : 01st of October 2006
  5. // ********************************
  6. #DllDeclare Kernel32( "CreateFile", "CloseHandle", "GetSystemTime", "SystemTimeToFileTime", "SetFileTime" )
  7.  
  8. Function Main()
  9.     Dim %lngHandle = NULL
  10.     Dim $szFileName * MAX_PATH+1
  11.     If CommandCount() = 2 Then
  12.         StrCpy( szFileName, Command(1) )
  13.         lngHandle = CreateFile(szFileName, GENERIC_WRITE, _
  14.                     FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
  15.         If lngHandle AndAlso lngHandle <> INVALID_HANDLE_VALUE Then
  16.             SetFileToCurrentTime( lngHandle )
  17.             CloseHandle( lngHandle )
  18.             Return 1 // => 1 will be the OK return
  19.         End If
  20.     End If
  21. Return 0 // => 0 will be the KO return
  22. End Function
  23.  
  24. Function SetFileToCurrentTime(Byval %hFile)
  25.   Dim $ft * 16 'FILETIME
  26.   Dim $st * 16 'SYSTEMTIME
  27.  
  28.   GetSystemTime(@st)                 // gets current time
  29.   SystemTimeToFileTime(@st, @ft)     // converts to file time format
  30.   Return SetFileTime(hFile, 0, 0, @ft) // sets last-write time for file
  31. End Function

See the attached Zip file to get the whole thing.
Enjoy FBSL !
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)
« Last Edit: October 01, 2006, 03:35 PM by Gerome »