You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The Code

Below is the code to call SetFileAttributes() to make C:\AREADING.TAB a read-only file with the archive bit set.  The attributes are set, and then GetFileAttributes() is called to prove that the

 

declare function SetFileAttributes, GetFileAttributes
filename = 'C:\areading.tab'
EQU FILE_ATTRIBUTE_READONLY$ to 1
EQU FILE_ATTRIBUTE_HIDDEN$   to 2
EQU FILE_ATTRIBUTE_SYSTEM$   to 4
EQU FILE_ATTRIBUTE_DIRECTORY$ to 16
EQU FILE_ATTRIBUTE_ARCHIVE$   to 32
/* NORMAL is a file with neither the readonly, hidden, nor archive bits set */
EQU FILE_ATTRIBUTE_NORMAL$    to 128
EQU FILE_ATTRIBUTE_TEMPORARY$ to 256
rv = SetFileAttributes (filename, FILE_ATTRIBUTE_READONLY$ + FILE_ATTRIBUTE_ARCHIVE$)
attributes = GetFileAttributes (filename)
if bitand( attributes , FILE_ATTRIBUTE_READONLY$) then
  call msg( filename : ' is a readonly file.')
end
if bitand( attributes , FILE_ATTRIBUTE_HIDDEN$) then
  call msg( filename : ' is hidden file.')
end
if bitand( attributes , FILE_ATTRIBUTE_SYSTEM$) then
  call msg( filename : ' is system file.')
end
if bitand( attributes , FILE_ATTRIBUTE_DIRECTORY$) then
  call msg( filename : ' is directory.')
end
if bitand( attributes , FILE_ATTRIBUTE_ARCHIVE$) then
  call msg( filename : ' is an archive file.')
end
if bitand( attributes , FILE_ATTRIBUTE_NORMAL$) then
  call msg( filename : ' is a normal file.')
end
if bitand( attributes , FILE_ATTRIBUTE_TEMPORARY$) then
  call msg( filename : ' is a temporary file.')
end
call msg(@window , 'attributes = ': attributes)

 

 

Note how the values for the attribute bits are added.  The attribute value returned from SetFileAttributes() is 33 (32 for the archive bit, plus 1 for the read-only bit).

The Windows API Declaration

The code above will not run until the declarations for GetFileAttributes() and SetFileAttributes() have been added.  To add the declaration, do the following:

  1. Log out of the application.

  2. Log into the SYSPROG application.

  3. Add a row, (call it DLL_APICALLS_KERNEL32), with the first line as KERNEL32 and containing the declarations as shown below.

 

KERNEL32
LONG STDCALL GetFileAttributesA(LPCHAR) as GetFileAttributes
LONG STDCALL SetFileAttributesA(LPCHAR, ULONG) as SetFileAttributes
//....add any other declarations in KERNEL32 here.....

 

 

The function is aliased to its ANSI version GetFileAttributesA().

      4. Save  the row.

      5. Run Declare_FCNS at the System Editor Exec Line to create the declaration header, as shown below:

RUN DECLARE_FCNS 'DLL_APICALLS_KERNEL32'

      6. Exit the editor.

      7. Log out of SYSPROG.

      8. Log into your application.

      9. Run the window.

  • No labels