关于如何在win98和winnt下同时实现共享,如pp点点通做的那样.有些问题请教.(50分)

  • 主题发起人 netfire_fly
  • 开始时间
N

netfire_fly

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在写的代码初衷是能在win98和win2000下都能实现.但现在遇到一些问题,主要是<br>实现共享得函数NetShareAdd()所使用得结构有些是win98独有,有些是win2000独有.<br>我现在要翻译一些结构...希望得到大家得帮助.<br><br>后面得不想贴了,大家知道怎么用了吧.<br>我查了msdn得部分,WinNT需要 一下得结构.关键是那些常量,我找不到定义.望帮助.<br>typedef struct _SHARE_INFO_502 {<br>&nbsp; LPWSTR &nbsp; &nbsp;shi502_netname;<br>&nbsp; DWORD &nbsp; &nbsp; shi502_type;<br>&nbsp; LPWSTR &nbsp; &nbsp;shi502_remark;<br>&nbsp; DWORD &nbsp; &nbsp; shi502_permissions;<br>&nbsp; DWORD &nbsp; &nbsp; shi502_max_uses;<br>&nbsp; DWORD &nbsp; &nbsp; shi502_current_uses;<br>&nbsp; LPWSTR &nbsp; &nbsp;shi502_path;<br>&nbsp; LPWSTR &nbsp; &nbsp;shi502_passwd;<br>&nbsp; DWORD &nbsp; &nbsp; shi502_reserved;<br>&nbsp; PSECURITY_DESCRIPTOR &nbsp;shi502_security_descriptor;<br>} SHARE_INFO_502, *PSHARE_INFO_502, *LPSHARE_INFO_502;<br>Members<br>shi502_netname <br>Pointer to a Unicode string specifying the name of a shared resource. <br>shi502_type <br>Specifies a DWORD value that indicates the type of share. Value Meaning <br>STYPE_DISKTREE Disk Drive <br>STYPE_PRINTQ Print Queue <br>STYPE_DEVICE Communication device <br>STYPE_IPC Interprocess communication (IPC) <br>STYPE_SPECIAL Special share reserved for interprocess communication (IPC$) or remote administration of the server (ADMIN$). Can also refer to administrative shares such as C$, D$, E$, and so forth. For more information, see the network management share functions. <br><br><br>shi502_remark <br>Pointer to a Unicode string specifying an optional comment about the shared resource. <br>shi502_permissions <br>Specifies a DWORD value that indicates the shared resource's permissions for servers running with share-level security. This member is ignored on a server running user-level security. This member can be any of the following values. Value Meaning <br>ACCESS_READ Permission to read data from a resource and, by default, to execute the resource. <br>ACCESS_WRITE Permission to write data to the resource. <br>ACCESS_CREATE Permission to create an instance of the resource (such as a file); data can be written to the resource as the resource is created. <br>ACCESS_EXEC Permission to execute the resource. <br>ACCESS_DELETE Permission to delete the resource. <br>ACCESS_ATRIB Permission to modify the resource's attributes (such as the date and time when a file was last modified). <br>ACCESS_PERM Permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application. <br>ACCESS_ALL Permission to read, write, create, execute, and delete resources, and to modify their attributes and permissions. <br><br><br>shi502_max_uses <br>Specifies a DWORD value that indicates the maximum number of concurrent connections that the shared resource can accommodate. The number of connections is unlimited if the value specified in shi502_max_uses is –1. <br>shi502_current_uses <br>Specifies a DWORD value that indicates the number of current connections to the resource. <br>shi502_path <br>Pointer to a Unicode string that contains the local path for the shared resource. For disks, shi502_path is the path being shared. For print queues, shi502_path is the name of the print queue being shared. <br>shi502_passwd <br>Pointer to a Unicode string that specifies the share's password (when the server is running with share-level security). If the server is running with user-level security, shi502_passwd is ignored. The shi502_passwd member can be no longer than SHPWLEN+1 bytes (including a terminating null character). <br>shi502_reserved <br>Reserved; must be zero. <br>shi502_security_descriptor <br>/////////////////////////以下是我写得部分代码/////////////////////////////////////<br><br>定义全局变量:<br>var MyHandle &nbsp; &nbsp; &nbsp; &nbsp; :THandle; &nbsp; <br>&nbsp; &nbsp; MyShareAdd &nbsp; &nbsp; &nbsp; :TMyShareAdd;<br>&nbsp; &nbsp; MyShareDel &nbsp; &nbsp; &nbsp; :TMyShareDel;<br>&nbsp; &nbsp; MyShareGetinfo &nbsp; :TMyShareGetinfo;<br>&nbsp; &nbsp; MyShareSetinfo &nbsp; :TMyShareSetinfo;<br>定义函数<br>type TMyShareAdd = function(ServerName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word):integer;Stdcall;<br>&nbsp; &nbsp; &nbsp;TMyShareDel = function (ServerName : PChar; NetName : PChar; Reserved : Word) : Integer; StdCall;<br>&nbsp; &nbsp; &nbsp;TMyShareGetinfo = function (ServerName : PChar; NetName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word; Var Used : Word) : Integer; StdCall;<br>&nbsp; &nbsp; &nbsp;TMyShareSetinfo =function (ServerName : PChar; NetName : PChar; ShareLevel : SmallInt; Buffer : Pointer; Size : Word; Reserved : SmallInt) : Integer; StdCall;<br>///////////////////////以下定义得是win98下使用得结构/////////////////////////<br>Type<br><br>&nbsp; Share_Info50 = Packed Record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_netname : Array[0..12] of Char; {13}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_type &nbsp; &nbsp;: Byte;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_flags &nbsp; : Word;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_remark &nbsp;: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_path &nbsp; &nbsp;: PChar;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_rw_password : Array[0..8] of Char; {9}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shi50_ro_password : Array[0..8] of Char;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End;<br><br>Const<br><br><br>{Resource Type Constants}<br>&nbsp; STYPE_DISKTREE = 0; {Directory Share}<br>&nbsp; STYPE_PRINTQ &nbsp; = 1; {Printer Share}<br><br>{Flag Constants}<br>&nbsp; SHI50F_RDONLY &nbsp;= 1; &nbsp;{ Share is Read Only}<br>&nbsp; SHI50F_FULL &nbsp; &nbsp;= 2; &nbsp;{ Share is Full Access}<br>&nbsp; SHI50F_DEPENDSON = (SHI50F_RDONLY or SHI50F_FULL); {Access depends upon password entered by user}<br><br>&nbsp; {OR the following with access constants to use them.<br>&nbsp; &nbsp;I.E.: flags := (SHI50F_RDONLY OR SHI50F_SYSTEM) }<br>&nbsp; SHI50F_PERSIST = 256; {The share is restored on system startup}<br>&nbsp; SHI50F_SYSTEM &nbsp;= 512; {The share is not normally visible}<br>////////////////////////////////定义结束////////////////////////////////////////<br>procedure TMain.initateSharewin98;<br><br>&nbsp; // MyHandle &nbsp; &nbsp; &nbsp; &nbsp; :THandle;<br>begin<br>&nbsp; &nbsp;MyHandle:=loadlibrary('Svrapi');<br>&nbsp; &nbsp;if MyHandle&lt;0 then<br>&nbsp; &nbsp;Raise Exception.Create('动态连接库调用失败,错误代码是:'+Inttostr(GetLasterror))<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;@MyShareAdd:=GetprocAddress(MyHandle,'NetShareAdd');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareAdd) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp; &nbsp;@MyShareDel:=GetprocAddress(Myhandle,'NetShareDel');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareDel) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp; &nbsp;@MyShareGetinfo:=GetProcAddress(Myhandle,'NetShareGetInfo');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareGetinfo) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp; &nbsp;@MySharesetinfo:=GetProcAddress(MYHandle,'NetshareSetinfo');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareSetinfo) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp;end;<br>end;<br><br>procedure TMain.InitateShare ;<br><br>&nbsp; // MyHandle &nbsp; &nbsp; &nbsp; &nbsp; :THandle;<br>begin<br>&nbsp; &nbsp;MyHandle:=loadlibrary('Netapi32');<br>&nbsp; &nbsp;if MyHandle&lt;0 then<br>&nbsp; &nbsp;Raise Exception.Create('动态连接库调用失败,错误代码是:'+Inttostr(GetLasterror))<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;@MyShareAdd:=GetprocAddress(MyHandle,'NetShareAdd');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareAdd) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp; &nbsp;@MyShareDel:=GetprocAddress(Myhandle,'NetShareDel');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareDel) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp; &nbsp;@MyShareGetinfo:=GetProcAddress(Myhandle,'NetShareGetInfo');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareGetinfo) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp; &nbsp;@MySharesetinfo:=GetProcAddress(MYHandle,'NetShareSetInfo');<br>&nbsp; &nbsp; &nbsp;if not Assigned(MyShareSetinfo) then<br>&nbsp; &nbsp; &nbsp; Raise Exception.Create('GetProcAdress 失败'+intToStr(Getlasterror) );<br>&nbsp; &nbsp;end;<br>end;<br>
 
顶部