谁会使用 WNetGetConnection (API)

Eric_Hu 2000-07-04 12:10:00
我根据 WIN32.hlp 里的格式写了如下的一段程序:

var lpLocalName,lpRemoteName:Pchar;
lpnLength: DWORD;
RtnValue : DWORD;
begin
tmp1:='D:\WIN98';//共享都设置好了
RtnValue := wnetgetconnection(lpLocalName,lpRemoteName,lpnLength);
showmessage(strpas(lpLocalName));
showmessage(strpas(lpRemoteName));
showmessage(inttostr(RtnValue));
end;

lpLocalName这个参数老不对,lpRemoteName没有返回值。
RtnValue 总返回“ERROR——BAD——DEVICE”(就是1200)

请高手指点
...全文
208 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
skt642 2001-05-31
  • 打赏
  • 举报
回复
5446关注!
Nicky_he 2000-11-07
  • 打赏
  • 举报
回复
正好我写过,给你了。
s1保留最后结果。
function TForm1.GetNetworkDriveMappings(s1:tstrings):integer;
var
i:integer;
sNetPath:string;
sLocalName:string;
s1Current:string;
dwMaxNetPathLen:DWord;
GetReturn:DWORD;
begin
s1.Clear;
dwMaxNetPathLen:=MAX_PATH;
SetLength(sNetPath,dwMaxNetPathLen);
for i:=3 to 25 do
begin
sLocalName:=''+Chr(65+i)+':';
GetReturn:=Windows.WNetGetConnection(PChar(sLocalName),PChar(sNetPath),dwMaxNetPathLen);
if (GetReturn=NO_ERROR) then
begin
s1Current:=inttostr(i)+'--'+chr(65+i)+':'+sNetPath;
s1.add(s1Current);
//sNetPath:='';
end;
GetReturn:=0;

end;
Result:=s1.Count;
end;
Wingsun 2000-07-04
  • 打赏
  • 举报
回复
你的用法有问题。因该如下:(BCB)
如果你将机器名为PC1所共享的目录D(表述为\\PC1\D)映射位你的本当地硬盘I:
此时Loc=I:函数返回RemoteName=\\PC1\D.Len为RemoteName的长度。
char Loc[255];
strcpy(Loc,Edit1->Text.c_str());
char RemoteName[255];
DWORD Len;
WNetGetConnection(Loc,RemoteName,&Len);
ShowMessage(RemoteName);

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧