home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / VOLDLL.ZIP / LABELDLL.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-02  |  6KB  |  212 lines

  1. {
  2. Steve Guimond    Compuserve 70253, 502
  3. July 2, 1993
  4. DLL to get and put disk volume labels, as well as other functions unavailable
  5. from visual basic
  6. This dll uses the TPW Unit VolFuncs.Pas, which Pat Ritchey wrote, Thanks Pat
  7.  
  8. Calling convention from visual basic
  9.  
  10. All return 0 if successful or 99 if not.
  11. Read_Label will return 0 if there is a label and 99 if there is not a label
  12.  
  13. Declare Function Set_Label Lib "labeldll.dll" (ByVal Drive%, ByVal NewLabel$) As Integer
  14. Declare Function Read_Label Lib "labeldll.dll" (ByVal Drive%, ByVal Label$) As Integer
  15. Declare Function Del_Label Lib "labeldll.dll" (ByVal Drive%) As Integer
  16.  
  17. Drive% (0 = Default, 1 = A, 2 = B, etc..)
  18.  
  19. *******************************************************************************************
  20.  
  21.     Type and function declarations for FindFirstFile and FindNextFile
  22.     Put the type declaration in the global module
  23.  
  24. Type FindDataType
  25.   reserved As String * 21
  26.   FileAttr As String * 1
  27.   FileTime As Long
  28.   FileSize As Long
  29.   FileName As String * 13
  30. End Type
  31.  
  32. Declare Function FindFirstFile Lib "d:\programs\labeldll.dll" (ByVal Path$, ByVal Attr%, FindData As FindDataType) As Integer
  33. Declare Function FindNextFile Lib "d:\programs\labeldll.dll" (FindData As FindDataType) As Integer
  34.  
  35. ********************************************************************************************
  36.  
  37.     Type and sub declaration for ConvertDateTime
  38.     The InDate& sent to the function is found in the FindDataType record FindDataType.FileTime (above)
  39.     you must first use FindFirstFile or FindNextFile to get the date then use ConvertDateTime
  40.     to convert the longint to english
  41.  
  42. Type DateTimeRec
  43.     year As Integer
  44.     month As Integer
  45.     day As Integer
  46.     hour As Integer
  47.     min As Integer
  48.     sec As Integer
  49. End Type
  50.  
  51. Declare Sub ConvertDateTime Lib "d:\programs\labeldll.dll" (ByVal InDate&, FindDate As DateTimeRec)
  52.  
  53. ********************************************************************************************
  54.  
  55. Functions to get total space and get free space left on a specified drive
  56.  
  57. Declare Function GetTotalSpace Lib "labeldll.dll" (ByVal Drive%) As Long
  58. Declare Function GetFreeSpace Lib "labeldll.dll" (ByVal Drive%) As Long
  59.  
  60. Return -1 if no space else return space in Bytes
  61.  
  62. ********************************************************************************************
  63.  
  64. }
  65. Library Label1;
  66.  
  67. Uses volfuncs, WinDos, Strings;
  68.  
  69.  
  70. {**************************************************************************}
  71.  
  72. Function Set_Label(Drive: Byte; P: PChar): Integer; Export;
  73.  
  74. Var
  75.    x, y: Integer;
  76.    NewLabel, a: VolString;
  77.    HasLabel, B: Boolean;
  78.    q: PChar;
  79. Begin
  80.              NewLabel := '';            { make sure newlabel is empty }
  81.              q := StrNew(P);            { make a copy of string sent in, directly modifying
  82.                                            string sent in will result in a GPF }
  83.              q := StrUpper(q);            { change string to upper case }
  84.              NewLabel := StrPas(q);        { convert to pascal style string }
  85.              StrDispose(q);             { get rid of temporary pointer }
  86.              HasLabel := GetLabel(Drive, a);     { check if a label exists }
  87.              If (Not HasLabel) Or DelLabel(Drive) Then     { if it has a label or deleting the
  88.                                                               label is successful then set label }
  89.                  B := SetLabel(Drive, NewLabel);
  90.              If B = True Then Set_Label := 0 Else Set_Label := 99;
  91.  
  92. End;
  93.  
  94. {*****************************************************************************}
  95.  
  96. Function Del_Label(Drive: Byte): Integer; Export;
  97.  
  98. Var
  99.     HasLabel: Boolean;
  100.     a: VolString;
  101.  
  102. Begin
  103.     HasLabel := GetLabel(Drive, a);
  104.     If (NOT HasLabel) Or DelLabel(Drive) Then Del_Label := 0 Else Del_Label := 99;
  105. End;
  106.  
  107. {*****************************************************************************}
  108.  
  109. Function Read_Label(Drive: Byte; P: PChar):Integer ; Export;
  110.  
  111. Var
  112.    x: Integer;
  113.    B: Boolean;
  114.    y: VolString;
  115.  
  116. Begin
  117.      If GetLabel(Drive, y) Then
  118.      Begin
  119.          Read_Label := 0;
  120.          For x := 0 to Length(y) - 1 do
  121.             Begin
  122.                 P[x] := y[x + 1];
  123.             End;
  124.      End
  125.      Else
  126.         Begin
  127.             Read_Label := 99;
  128.             For x := 0 To 10 do
  129.                 P[x] := ' ';
  130.         End;
  131.  
  132. End;
  133.  
  134. {*****************************************************************************}
  135.  
  136. Function FindFirstFile(Path: PChar; Attr: Word; Var F: TSearchRec): Integer ; Export;
  137.  
  138. Begin
  139.     F.Name := '             ';
  140.     F.Size := 0;
  141.     F.Time := 0;
  142.     FindFirst(Path, Attr, F);
  143.     FindFirstFile := DosError;
  144. End;
  145.  
  146. {*****************************************************************************}
  147.  
  148. Function FindNextFile(Var F: TSearchRec): Integer; Export;
  149.  
  150. Begin
  151.     F.Name := '             ';
  152.     F.Size := 0;
  153.     F.Time := 0;
  154.     FindNext(F);
  155.     FindNextFile := DosError;
  156. End;
  157.  
  158. {****************************************************************************}
  159.  
  160. Function GetTotalSpace(Drive: Byte): LongInt; Export;
  161.  
  162. Var
  163.     v: LongInt;
  164.  
  165. Begin
  166.     v := DiskSize(Drive);
  167.     If v = -1 Then GetTotalSpace := -1
  168.     Else
  169.         GetTotalSpace := v;
  170. End;
  171.  
  172. {***************************************************************************}
  173.  
  174. Function GetFreeSpace(Drive: Byte): LongInt; Export;
  175.  
  176. Var
  177.     v: LongInt;
  178.  
  179. Begin
  180.     v := DiskFree(Drive);
  181.     If v = -1 Then GetFreeSpace := -1
  182.     Else
  183.         GetFreeSpace := v;
  184. End;
  185.  
  186. {**************************************************************************}
  187.  
  188. Procedure ConvertDateTime(DateTime: LongInt; Var DT: TDateTime); Export;
  189.  
  190. Begin
  191.     UnPackTime(DateTime, DT);
  192. End;
  193.  
  194. {*************************************************************************}
  195.  
  196.  
  197. Exports
  198.        Set_Label,
  199.        Read_Label,
  200.        FindFirstFile,
  201.        FindNextFile,
  202.        Del_Label,
  203.        GetTotalSpace,
  204.        GetFreeSpace,
  205.        ConvertDateTime;
  206.  
  207. Begin
  208.  
  209. End.
  210.                                       
  211.  
  212.