Windows TNetSharingManager访问冲突问题
我试图在Delphi2010中编译它,它使用TNetSharingManager。我已导入类型库并尝试编译它,但不幸的是,我在此函数中遇到访问冲突: function TNetSharingManager.GetDefaultInterface: INetSharingManager; begin if FIntf = nil then Connect; Assert(FIntf nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call "Connect" or "ConnectTo" before this operation'); Result := FIntf; end;Windows TNetSharingManager访问冲突问题,windows,delphi,api,networking,adapter,Windows,Delphi,Api,Networking,Adapter,我试图在Delphi2010中编译它,它使用TNetSharingManager。我已导入类型库并尝试编译它,但不幸的是,我在此函数中遇到访问冲突: function TNetSharingManager.GetDefaultInterface: INetSharingManager; begin if FIntf = nil then Connect; Assert(FIntf nil, 'DefaultInterface is NULL. Component is not
我不明白为什么我不能与nil相比。有什么想法吗?触发该错误时,TNetSharingManager对象本身很可能已经死亡(或者根本没有创建)。FIntF=nil表达式是对类的实际字段的第一个引用,即它将指向无效的地址空间 [编辑]我下载了源代码并按照步骤导入TLB(Delphi 2010)。为了执行应用程序,我必须(a)以管理员的身份运行Delphi,因为默认情况下我不是超级用户,(b)必须添加对pUser nil的检查,因为最终的getProperties返回一个nil结构,但代码运行良好。很不幸,我似乎无法重现你的问题
重读您的问题,您是否在编译时获得AV 谢谢你的回答,Paul Jan,我已经尝试了很多方法来解决这个问题,我自己创建了对象(和成员对象)。[错误地按enter键]…但是运气不好。我应该提到:FIntf:INetSharingManager;真正让我吃惊的是,这段代码是在Delphi7中编写的(作为原始项目)。这意味着包装器有问题。在我看来,似乎没有人关注这些单位,这是一个遗憾,考虑到这是互联网上管理网络连接的极少数例子之一。再次感谢!刚刚注意到编辑。非常感谢你的努力!很高兴知道它仍然有效!不幸的是,我仍然无法运行它(即使它编译时没有错误)。我会继续努力,希望很快能成功。 procedure TForm1.GetConnectionList(Strings,IdList: TStrings); var pEnum: IEnumVariant; vNetCon: OleVARIANT; dwRetrieved: Cardinal; pUser: NETCONLib_TLB.PUserType1; NetCon : INetConnection; begin Strings.Clear; IdList.Clear; pEnum := ( NetSharingManager.EnumEveryConnection._NewEnum as IEnumVariant); while (pEnum.Next(1, vNetCon, dwRetrieved) = S_OK) do begin (IUnknown(vNetCon) as INetConnection).GetProperties(pUser); NetCon := (IUnknown(vNetCon) as INetConnection); if (pUser.Status in [NCS_CONNECTED,NCS_CONNECTING])//remove if you want disabled NIC cards also and (pUser.MediaType in [NCM_LAN,NCM_SHAREDACCESSHOST_LAN,NCM_ISDN] ) and (GetMacAddress(GuidToString(pUser.guidId))'' ) then begin //we only want valid network cards that are enabled Strings.Add(pUser.pszwName ); IdList.Add(GuidToString(pUser.guidId)); end; end; end;