2
我想在Delphi 2010中使用TNetSharingManager來編譯這個project。我已經導入類型庫,並試圖編譯它,但不幸的是我在這個函數得到一個訪問衝突: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;
我不明白爲什麼我不能零比較。有任何想法嗎?
感謝您的回答Paul-Jan,我嘗試了很多方法通過自己創建對象(和成員對象)來解決問題。 – 2010-10-17 22:09:29
[按錯誤輸入] ..但沒有運氣。我應該提到:FIntf:INetSharingManager;真正令我驚訝的是,這個代碼在Delphi 7中編譯(作爲原始項目)。這意味着包裝有問題。在我看來,沒有人對這些單位給予任何關注,可惜,考慮到這是互聯網管理網絡連接的極少數例子之一。再次感謝! – 2010-10-17 22:16:37
剛剛注意到編輯。非常感謝你的努力!很高興知道它仍然有效!不幸的是,我仍然無法運行它(即使編譯沒有錯誤)。我會繼續努力,希望能儘快完成。 – 2010-10-19 00:55:10