I'm trying to compile this project in Delphi 2010, which uses TNetSharingManager. I have imported the type library and tried compiling it, but unfortunately I'm getting an Access Violation in this function:
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;
(part of NETCONLib_TLB)
The error is in : if FIntf = nil then
for some odd reason..
The code which is calling it:
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;
I don't understand why I cannot compare with nil. Any ideas?