C# COM NLA 错误 HRESULT 0x80040202
C# COM NLA error HRESULT 0x80040202
好的,所以我正在尝试使用 System.Runtime.InteropServices.ComTypes
中的 NetworkListManager
使用此代码设置网络连接事件:
private NetworkListManager nlm; //This is initialized before
private IConnectionPoint icp;
private int cookie = 0;
//This part is wrapped in a function call
Console.WriteLine("Subscribing the INetworkListManagerEvents");
IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
icpc.FindConnectionPoint(ref tempGuid, out icp);
//The error is thrown in icp.Advise with code 0x80040202
icp.Advise(this, out cookie);
我已经尝试过搜索,但大多数人对这个错误有不同的关注
NETWORKLIST
的正确使用方法是这样的:
using NETWORKLIST;
public class Foo : INetworkListManagerEvents
{
private NetworkListManager nlm;
private IConnectionPoint icp;
private int cookie = 0;
public Foo()
{
nlm = new NetworkListManager();
IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
icpc.FindConnectionPoint(ref tempGuid, out icp);
icp.Advise(this, out cookie);
}
//this method must be implemented
public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
{
//Your code goes here
}
}
我做错的是我忘了实现INetworkListManagerEvents
好的,所以我正在尝试使用 System.Runtime.InteropServices.ComTypes
中的 NetworkListManager
使用此代码设置网络连接事件:
private NetworkListManager nlm; //This is initialized before
private IConnectionPoint icp;
private int cookie = 0;
//This part is wrapped in a function call
Console.WriteLine("Subscribing the INetworkListManagerEvents");
IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
icpc.FindConnectionPoint(ref tempGuid, out icp);
//The error is thrown in icp.Advise with code 0x80040202
icp.Advise(this, out cookie);
我已经尝试过搜索,但大多数人对这个错误有不同的关注
NETWORKLIST
的正确使用方法是这样的:
using NETWORKLIST;
public class Foo : INetworkListManagerEvents
{
private NetworkListManager nlm;
private IConnectionPoint icp;
private int cookie = 0;
public Foo()
{
nlm = new NetworkListManager();
IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
Guid tempGuid = typeof(INetworkListManagerEvents).GUID;
icpc.FindConnectionPoint(ref tempGuid, out icp);
icp.Advise(this, out cookie);
}
//this method must be implemented
public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
{
//Your code goes here
}
}
我做错的是我忘了实现INetworkListManagerEvents