Microsoft KB Archive/126454

{| = How to Set File Attributes: Use C to Create FLL & Then Call It =
 * width="100%"|

ID: Q126454

The information in this article applies to:


 * Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a

SUMMARY
You can change the attributes of a file in FoxPro for Windows without performing a RUN ATTRIB. This article contains:


 * The C code you need to create an FLL.
 * The FoxPro code you need to call the FLL.

C Code to Create an FLL that Can Be Called from FoxPro

 * 1) include 
 * 2) include 

void FAR SetFA(ParamBlk FAR *parm) {
 * 1) define FN (parm->p[0].val)
 * 2) define FA (parm->p[1].val)

char FAR *FName; unsigned FAttr, retst; if(!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1))

// null terminate string {  _Error(182); } _HLock(FN.ev_handle); _HLock(FA.ev_handle); FName = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); FName[parm->p[0].val.ev_length] = '\0';

FAttr = (unsigned) FA.ev_long; // set FAttr value and convert second

// attribute from integer to unsigned.

retst=_dos_setfileattr(FName, FAttr);  // change file attribute _HUnLock(FN.ev_handle); _HUnLock(FA.ev_handle); _RetInt(retst, 10); // return success or failure (0 = success) otherwise DOS

error } FoxInfo myFoxInfo[] = {

{"ATTRIB", (FPFI) SetFA, 2, "C, I"}, }; FoxTable _FoxTable = {

(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo };

FoxPro Code Sample Showing How to Use the FLL
The following FoxPro code shows by example how to use the FLL to change the attributes of the file CUSTOMER.DBF to read only, and then reset all of the attributes. Also included is a table showing what each of the numbers means to the function _dos_setfileattr.

* Table of properties for _dos_setfileattr: * 0 - unset all attributes * 1 - read only * 2 - hidden * 3 - read only/hidden * 4 - system * 5 - read only/system * 6 - hidden/system * 7 - read only/hidden/system

SET LIBRARY TO SYS(2004)+"fileattr.fll" FileStat=ATTRIB("C:\FOXPROW\TUTORIAL\CUSTOMER.DBF",1) IF FileStat=0 WAIT WINDOW "Attribute of CUSTOMER.DBF set to read only" ELSE WAIT WINDOW "DOS Error: "+STR(FileStat)+" setting file attribute" ENDIF FileStat=ATTRIB("C:\FOXPROW\TUTORIAL\CUSTOMER.DBF",0) IF FileStat=0 WAIT WINDOW "Attribute of CUSTOMER.DBF reset" ELSE WAIT WINDOW "DOS Error: "+STR(FileStat)+" setting file attribute" ENDIF SET LIBRARY TO Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbtool kbcode kbprg KBSubcategory: FxtoolLck
 * }