代码之家  ›  专栏  ›  技术社区  ›  Ed.C

tNetsharingManager访问冲突问题

  •  2
  • Ed.C  · 技术社区  · 15 年前

    我正试图编译这个 project 在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;
    

    (netconlib_tlb的一部分) 错误出现在: if FIntf = nil then 出于某种奇怪的原因……

    调用它的代码:

    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;
    

    我不明白为什么我不能和 . 有什么想法吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Paul-Jan    15 年前

    当触发该错误时,tNetsharingManager对象本身很可能已经死亡(或者不是最初创建的)。这个 FIFTF=零 表达式是对类的实际字段的第一个引用,即它将指向无效的地址空间。

    [编辑] 我下载源代码并按照步骤导入TLB(Delphi2010)。为了执行应用程序,我必须(a)以管理员身份运行Delphi,因为默认情况下我不是超级用户,(b)必须添加一个 puser<gt;无 因为最终的getproperties返回一个nil结构,但除此之外,代码运行良好。所以不幸的是,我似乎无法重现你的问题。

    重读你的问题,你有没有一段时间的AV 编译 ?