为98设共享为何总是出错,返回值为2116?(60分)

  • 主题发起人 主题发起人 lufang
  • 开始时间 开始时间
L

lufang

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
unit Netshare;
interface

uses Windows, classes,SysUtils;

type
TShareInfo2 = packed record
shi2_netname: PWChar;
shi2_type: DWORD;
shi2_remark: PWChar;
shi2_permissions: DWORD;
shi2_max_uses: DWORD;
shi2_current_uses: DWORD;
shi2_path: PWChar;
shi2_passwd: PWChar;
end;
PShareInfo2 = ^TShareInfo2;
TShareInfo2Array = array[0..512] of TShareInfo2;
PShareInfo2Array = ^TShareInfo2Array;

type
TShareInfo50 = packed record
shi50_netname: array[0..12] of Char;
shi50_type: Byte;
shi50_flags: Word;
shi50_remark: PChar;
shi50_path: PChar;
shi50_rw_password: array[0..8] of Char;
shi50_ro_password: array[0..8] of Char;
end;
var
NetShareDelNT: function(servername: PWideChar; netname: PWideChar; reserved: DWORD): LongInt; stdcall;
NetShareDel: function(pszServer, pszNetName: PChar; usReserved: Word): DWORD; stdcall;
NetShareAddNT: function(servername: PWideChar; level: DWORD; buf: Pointer; parm_err: LPDWORD): DWORD; stdcall;
NetShareAdd: function(pszServer: PChar; sLevel: Cardinal;pbBuffer: PChar; cbBuffer: Word): DWORD; stdcall;
function AddShare(ShareName, ShareDir: string):integer;
function IsWinNT: Boolean;

implementation


function IsWinNT: Boolean;
var
VersionInfo: TOSVersionInfo;
begin
VersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
Result := GetVersionEx(VersionInfo);
if Result then
Result := VersionInfo.dwPlatformID = VER_PLATFORM_WIN32_NT;
end;


procedure CloseShare(ShareName: string);
var
OS: Boolean;
FLibHandle: THandle;
Name9x: array[0..12] of Char;
NameNT: PWChar;
i: integer;
begin
os:=isWinNT;
if OS then begin
FLibHandle := LoadLibrary('NETAPI32.DLL');
if FLibHandle = 0 then Exit;
@NetShareDelNT := GetProcAddress(FLibHandle, 'NetShareDel');
if not Assigned(NetShareDelNT) then
begin
FreeLibrary(FLibHandle);
Exit;
end;
i := SizeOf(WideChar) * 256;
GetMem(NameNT, i);
StringToWideChar(ShareName, NameNT, i);
NetShareDelNT(nil, NameNT, 0);
FreeMem(NameNT);
end else begin
FLibHandle := LoadLibrary('SVRAPI.DLL');
if FLibHandle = 0 then Exit;
@NetShareDel := GetProcAddress(FLibHandle, 'NetShareDel');
if not Assigned(NetShareDel) then
begin
FreeLibrary(FLibHandle);
Exit;
end;
FillChar(Name9x, SizeOf(Name9x), #0);
move(ShareName[1], Name9x[0], Length(ShareName));
NetShareDel(nil, @Name9x, 0);
end;
FreeLibrary(FLibHandle);
end;

function AddShare(ShareName, ShareDir: string):integer;
const
STYPE_DISKTREE = 0;
ACCESS_ALL = 258;
SHI50F_FULL = 258;
var
FLibHandle: THandle;
Share9x: TShareInfo50;
ShareNT: TShareInfo2;
TmpDirNT, TmpNameNT: PWChar;
OS: Boolean;
TmpLength: integer;
begin
os:=isWinNT;

if OS then begin
FLibHandle := LoadLibrary('NETAPI32.DLL');
if FLibHandle = 0 then
begin
result:=-1;
Exit;
end;
@NetShareAddNT := GetProcAddress(FLibHandle, 'NetShareAdd');
if not Assigned(NetShareAddNT) then
begin
FreeLibrary(FLibHandle);
result:=-1;
Exit;
end;
TmpLength := SizeOf(WideChar) * 256;

GetMem(TmpNameNT, TmpLength);
StringToWideChar(ShareName, TmpNameNT, TmpLength);
ShareNT.shi2_netname := TmpNameNT;

ShareNT.shi2_type := STYPE_DISKTREE;
ShareNT.shi2_remark := '';
ShareNT.shi2_permissions := ACCESS_ALL;
ShareNT.shi2_max_uses := DWORD(-1);
ShareNT.shi2_current_uses := 0;

GetMem(TmpDirNT, TmpLength);
StringToWideChar(ShareDir, TmpDirNT, TmpLength);
ShareNT.shi2_path := TmpDirNT;

ShareNT.shi2_passwd := '';

result:=NetShareAddNT(nil, 2, @ShareNT, nil);
FreeMem(TmpNameNT);
FreeMem(TmpDirNT);
end else begin
FLibHandle := LoadLibrary('SVRAPI.DLL');
if FLibHandle = 0 then
begin
result:=-1;
Exit;
end;
@NetShareAdd := GetProcAddress(FLibHandle, 'NetShareAdd');
if not Assigned(NetShareAdd) then
begin
FreeLibrary(FLibHandle);
result:=-2;
Exit;
end;
FillChar(Share9x.shi50_netname, SizeOf(Share9x.shi50_netname), #0);
move(ShareName[1], Share9x.shi50_netname[0], Length(ShareName));
Share9x.shi50_type := STYPE_DISKTREE;
Share9x.shi50_flags := SHI50F_FULL;
FillChar(Share9x.shi50_remark,SizeOf(Share9x.shi50_remark), #0);
FillChar(Share9x.shi50_path,SizeOf(Share9x.shi50_path), #0);
// Share9x.shi50_path := PAnsiChar(ShareDir);
Share9x.shi50_path := PChar(ShareDir);
FillChar(Share9x.shi50_rw_password,SizeOf(Share9x.shi50_rw_password), #0);
FillChar(Share9x.shi50_ro_password,SizeOf(Share9x.shi50_ro_password), #0);
result:=NetShareAdd(nil, 50, @Share9x, SizeOf(Share9x));
end;
FreeLibrary(FLibHandle);
end;

end.
2000、XP下执行正常,98下总是返回2116,请问是怎么回事,该如何解决?
 
可能是有些新函数在xp下支持,在98下面不支持吧。
 
不好意思,自己顶下
 

Similar threads

I
回复
0
查看
773
import
I
I
回复
0
查看
589
import
I
I
回复
0
查看
444
import
I
I
回复
0
查看
501
import
I
后退
顶部