Source file: /~heha/hsn/wnetdrv.zip/WNETDRV.PAS

library WNetdrv;
{$C MOVEABLE PRELOAD PERMANENT}	{gleiche Attribute wie Unit SYSTEM}
{$DEFINE LONGNAMES}
{ DEFINE NETWARE}
{$W-,S-,G+}
uses winprocs,wintypes,win31,LFN;
{$IFDEF NETWARE}
function Int215F(Func:Byte; RegBX:Word; Local,Remote:PChar):Integer; assembler;
asm	push	ds
	push	bp
	 mov	cx,4E57h
	 mov	bx,[RegBX]
	 lds	si,[Local]
	 les	di,[Remote]
	 mov	ah,5Fh
	 mov	al,[Func]
	 int	21h
	pop	bp
	pop	ds
end;

function PutString(SS,SD: PChar; var SLen: Word):Word;
 var
  W: Word;
 begin
  PutString:=0;
  W:=Word(lstrlen(SS));
  if SLen<W+1 then begin
   lstrcpyn(SD,SS,SLen);
   PutString:=2;		{WN_More_Data}
  end else begin
   lstrcpy(SD,SS);
   SLen:=W;
  end;
 end;
{$ENDIF}

function WNetGetCaps(Idx:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetCaps:=0;		{Alle anderen Funktionen}
  case Idx of
   1: WNetGetCaps:=$0300;	{Windows-Version}
{$IFDEF NETWARE}
   2: WNetGetCaps:=$0300;	{Netware}
   6: WNetGetCaps:=$0007;	{Add/Cancel/GetConnection(/BrowseDialog)}
{$ENDIF}
{$IFDEF LONGNAMES}
   9: WNetGetCaps:=$0004;	{Lange Dateinamen (Laufwerk D:)}
{$ENDIF}
  end;
 end;

{$IFDEF NETWARE}
function WNetAddConnection(NetPath,PassWord,LocalName:PChar):Word; export;
 var
  S: array[0..128] of Char;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  lstrcpy(S,NetPath);
  if PassWord<>nil then lstrcpy(S+lstrlen(S)+1,PassWord);
  WNetAddConnection:=Int215F(3,4,LocalName,S);
 end;

function WNetCancelConnection(Name:PChar; Force:Bool):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetCancelConnection:=Int215F(4,4,Name,nil);
 end;

procedure Enable; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
 end;

procedure Disable; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
 end;

function WNetAbortJob(Queue:PChar;fh:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetAbortJob:=1;
 end;

function WNetBrowseDialog(Parent:HWnd; Typ:Word; Path:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  MessageBox(Parent,'Hallo!',nil,0);
  Path[0]:=#0;
  WNetBrowseDialog:=0;
 end;

function WNetCancelJob(Queue:PChar;JobID:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetCancelJob:=1;
 end;

function WNetCloseJob(fh:Word; var JobID:Word; Queue:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetCloseJob:=1;
 end;

function WNetConnectDialog(Parent:HWnd; Typ:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetConnectDialog:=1;
 end;

function WNetConnectionDialog(Parent:HWnd; Typ:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetConnectionDialog:=1;
 end;

function WNetDeviceMode(Parent:HWnd):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetDeviceMode:=1;
 end;

function WNetDirectoryNotify(Parent:HWnd;Dir:PChar;Oper:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetDirectoryNotify:=1;
 end;

function WNetDisconnectDialog(Parent:HWnd; Typ:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetDisconnectDialog:=1;
 end;

function WNetGetConnection(Local,Remote:PChar; var BufSize:Word):Word; export;
 var
  I: Integer;
  LW: array[0..15] of Char;
  S: array[0..127] of Char;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetConnection:=1;
  I:=0;
  repeat
   if Int215F(2,I,LW,S)<>0 then exit;
   if lstrcmpi(Local,LW)=0 then begin
    WNetGetConnection:=PutString(S,Remote,BufSize);
    exit;
   end;
   Inc(I);
  until false;
 end;

function WNetGetDirectoryType(Name:PChar; var BufSize:Integer):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetDirectoryType:=1;
 end;

function WNetGetError(var err:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetError:=1;
 end;

function WNetGetErrorText(err:Word; Buf:PChar; var BufSize:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetErrorText:=1;
 end;

function WNetGetPropertyText(Button,PropSel:Word;Name,ButtonName:PChar;
  BNSize,Typ:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetPropertyText:=1;
 end;

function WNetGetUser(Buf:PChar; var BufSize:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetGetUser:=1;
 end;

function WNetHoldJob(Queue:PChar;JobID:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetHoldJob:=1;
 end;

function WNetLockQueueData(Queue,User:PChar; var QS):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetLockQueueData:=1;
 end;

function WNetOpenJob(Queue,Title:PChar; Copies:Word; var fh:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetOpenJob:=1;
 end;

function WNetPropertyDialog(Parent:HWnd;Button,PropSel:Word;Name:PChar;
  Typ:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetPropertyDialog:=1;
 end;

function WNetReleaseJob(Queue:PChar;JobID:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetReleaseJob:=1;
 end;

function WNetRestoreConnection(Parent:HWnd;Device:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetRestoreConnection:=1;
 end;

function WNetSetJobCopies(Queue:PChar;JobID,Copies:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetSetJobCopies:=1;
 end;

function WNetUnlockQueueData(Queue:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetUnlockQueueData:=1;
 end;

function WNetUnwatchQueue(Local:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetUnwatchQueue:=1;
 end;

function WNetViewQueueDialog(Parent:HWnd;Queue:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetViewQueueDialog:=1;
 end;

function WNetWatchQueue(Wnd:HWnd;Local,User:PChar; Queue:Word):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetWatchQueue:=1;
 end;

function WNetWriteJob(Job:THandle; Data:PChar; var DataLen:Integer):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  WNetWriteJob:=1;
 end;
{$ENDIF}

{$IFDEF LONGNAMES}
type
 TFileFindBuf2=record
  tCreation,tLastAccess,tLastWrite: LongInt;
  Size,Alloc: LongInt;
  Attr: Word;
  EASize: LongInt;
  NameLen: Byte;
  Name: array[0..255] of Char;
 end;

{ UseCurTime: boolean=TRUE;
 UseTimeWord: boolean=FALSE;
 UseDateWord: boolean=FALSE;}

function SwapL(A:LongInt):LongInt;
inline($5A/$58);		{pop dx; pop ax}

procedure FillFindBuf(const SR: TWin32FindData; var Find: TFileFindBuf2);
 begin
  Find.tCreation:=SwapL(SR.timec.lo);
  Find.tLastAccess:=SwapL(SR.timea.lo);
  Find.tLastWrite:=SwapL(SR.timem.lo);
  Find.Size:=SR.sizel;
  Find.Alloc:=SR.sizel;
  Find.Attr:=SR.attr;
  Find.EASize:=0;
  lstrcpy(Find.Name,SR.namel);
  Find.NameLen:=lstrlen(Find.Name);
 end;

function LFNFindFirst(Filter:PChar; Attr:Word; var Entries:Word;
  var hDir:Word; BufSize:Word; var Find:TFileFindBuf2):Word; export;
  assembler;
 var
  SR: TWin32FindData;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	push	ds
	 mov	ax,714Eh
	 mov	cx,[Attr]
	 lds	dx,[Filter]
	 mov	si,1		{OEM return}
	 push	ss
	 pop	es
	 lea	di,SR
	 stc
	 int	21h
	pop	ds
	mov	dx,0		{Find Handle in case of error}
	mov	cx,dx		{number of DirEnts}
	jc	@@err
	push	ax		{Find Handle}
	 push	es
	 push	di
	 les	di,[Find]
	 push	es
	 push	di
	 call	FillFindBuf
	pop	dx		{Find Handle}
	xor	ax,ax		{Error Code =0}
	mov	cx,1		{number of DirEnts}
@@err:	push	ax
	 les	di,[hDir]
	 xchg	dx,ax
	 stosw
	 les	di,[Entries]
	 xchg	cx,ax
	 stosw
	pop	ax
 end;

function LFNFindNext(hDir:Word; var Entries:Word;
  BufSize:Word; var Find:TFileFindBuf2):Word; export;
  assembler;
 var
  SR: TWin32FindData;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,714Fh
	mov	bx,[hDir]
	push	ss
	pop	es
	lea	di,SR
	stc
	int	21h
	mov	cx,0
	jc	@@err
	push	es
	push	di
	les	di,[Find]
	push	es
	push	di
	call	FillFindBuf
	xor	ax,ax		{Error Code =0}
	mov	cx,1		{number of DirEnts}
@@err:	push	ax
	 les	di,[Entries]
	 xchg	cx,ax
	 stosw
	pop	ax
 end;

function LFNFindClose(hDir:Word):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,71A1h
	mov	bx,[hDir]
	stc
	int	21h
	jc	@@err
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNVolumeType(Drv:Word; var Typ: Integer):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	les	di,[Typ]
	mov	ax,1		{= VOLUME_LONGNAMES}
	stosw
	dec	ax
 end;

function LFNGetVolumeLabel(Drv:Word; S:PChar):Word; export; assembler;
 var
  RootName: array[0..4] of Char;
  SR: TWin32FindData;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,[Drv]
	add	al,'@'
	push	ss
	pop	es
	lea	di,RootName
	cld
	stosb
	mov	ax,'\:'
	stosw
	mov	ax,'*'
	stosw			{build "drive:\*"}
	push	ds
	 mov	ax,714Eh
	 mov	cx,8		{search attribute (only)}
	 push	ss
	 pop	ds
	 lea	dx,RootName
	 mov	si,1
	 lea	di,SR		{ES is already set}
	 stc
	 int	21h
	pop	ds
	jc	@@err
	xchg	bx,ax
	mov	ax,71A1h	{close find handle}
	int	21h		{cannot handle error here}
	push	ss
	lea	ax,SR.namel
	push	ax
	les	ax,[S]
	push	es
	push	ax
	call	lstrcpy		{copy to client buffer}
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNCopy(S,D:PChar; Proc:Pointer):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  LFNCopy:=1;
 end;

function LFNDelete(S:PChar):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,7141h
	push	ds
	 lds	dx,[S]
	 stc
	 int	21h
	pop	ds
	jc	@@err
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNGetAttributes(S:PChar; var Attr: Word):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,7143h
	mov	bl,0
	push	ds
	 lds	dx,[S]
	 stc
	 int	21h
	pop	ds
	jc	@@err
	les	di,[Attr]
	xchg	cx,ax
	stosw
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNMkDir(S:PChar):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,7139h
	push	ds
	 lds	dx,[S]
	 stc
	 int	21h
	pop	ds
	jc	@@err
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNMove(S,D:PChar):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,7156h
	push	ds
	 lds	dx,[S]
	 les	di,[D]
	 stc
	 int	21h
	pop	ds
	jc	@@err
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNParse(S,M,D:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  lstrcpy(D,S);
  if lstrlen(M)<>0 then asm int 1 end;
  LFNParse:=0;
  while S^<>#0 do begin
   if S^ in ['a'..'z'] then begin
    LFNParse:=2;		{Langer Dateiname bei Kleinbuchstaben}
    break;
   end;
   Inc(S);
  end;
 end;

function LFNRmDir(S:PChar):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,713Ah
	push	ds
	 lds	dx,[S]
	 stc
	 int	21h
	pop	ds
	jc	@@err
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNSetAttributes(S:PChar; Attr: Word):Word; export; assembler;
 asm
  {$IFOPT D+} int 3 {$ENDIF}
	mov	ax,7143h
	mov	bl,1
	mov	cx,[Attr]
	push	ds
	 lds	dx,[S]
	 stc
	 int	21h
	pop	ds
	jc	@@err
	xor	ax,ax		{Error Code =0}
@@err:
 end;

function LFNSetVolumeLabel(Drv:Word; S:PChar):Word; export;
 begin
  {$IFOPT D+} asm int 3 end; {$ENDIF}
  LFNSetVolumeLabel:=1;
 end;
{$ENDIF}

exports
{$IFDEF NETWARE}
 WNetOpenJob		index 1,
 WNetCloseJob		index 2,
 WNetAbortJob		index 3,
 WNetHoldJob		index 4,
 WNetReleaseJob		index 5,
 WNetCancelJob		index 6,
 WNetSetJobCopies	index 7,
 WNetWatchQueue		index 8,
 WNetUnwatchQueue	index 9,
 WNetLockQueueData	index 10,
 WNetUnlockQueueData	index 11,
 WNetGetConnection	index 12,
{$ENDIF}
 WNetGetCaps		index 13
{$IFDEF NETWARE}
,WNetDeviceMode		index 14,
 WNetBrowseDialog	index 15,
 WNetGetUser		index 16,
 WNetAddConnection	index 17,
 WNetCancelConnection	index 18,
 WNetGetError		index 19,
 WNetGetErrorText	index 20,
 WNetRestoreConnection	index 23,
 WNetWriteJob		index 24,
 WNetConnectDialog	index 25,
 WNetDisconnectDialog	index 26,
 WNetConnectionDialog	index 27,
 WNetViewQueueDialog	index 28,
 WNetPropertyDialog	index 29,
 WNetGetDirectoryType	index 30,
 WNetDirectoryNotify	index 31,
 WNetGetPropertyText	index 32,
 Enable			index 33,
 Disable		index 34
{$ENDIF}
{$IFDEF LONGNAMES}
,LFNFindFirst		index 100,
 LFNFindNext		index 101,
 LFNFindClose		index 102,
 LFNGetAttributes	index 103,
 LFNSetAttributes	index 104,
 LFNCopy		index 105,
 LFNMove		index 106,
 LFNDelete		index 107,
 LFNMkDir		index 108,
 LFNRmDir		index 109,
 LFNGetVolumeLabel	index 110,
 LFNSetVolumeLabel	index 111,
 LFNParse		index 112,
 LFNVolumeType		index 113
{$ENDIF};
begin
end.
Detected encoding: ASCII (7 bit)2