我正在向我的 .NET Compact Framework 3.5 应用程序添加 Windows Mobile Connection Manager 支持。
我需要向用户隐藏连接错误,我已经阅读了 MSDN 文档并遵循它(据我所知),但如果 GPRS 连接失败,它们仍然会不断弹出。
这是我的 C# 代码:
这是 ConnMgrConnectionInfo 结构的托管包装器:
[StructLayout(LayoutKind.Sequential)]
public sealed class ConnMgrConnectionInfo
{
Int32 cbSize; // DWORD
public ConnMgrParam dwParams = 0; // DWORD
public ConnMgrProxy dwFlags = 0; // DWORD
public ConnMgrPriority dwPriority = 0; // DWORD
public Int32 bExclusive = 0; // BOOL
public Int32 bDisabled = 0; // BOOL
public Guid guidDestNet = Guid.Empty; // GUID
public IntPtr hWnd = IntPtr.Zero; // HWND
public UInt32 uMsg = 0; // UINT
public Int32 lParam = 0; // LPARAM
public UInt32 ulMaxCost = 0; // ULONG
public UInt32 ulMinRcvBw = 0; // ULONG
public UInt32 ulMaxConnLatency = 0; // ULONG
// Constructors
public ConnMgrConnectionInfo()
{
cbSize = Marshal.SizeOf(typeof(ConnMgrConnectionInfo));
}
public ConnMgrConnectionInfo(Guid destination, ConnMgrPriority priority, ConnMgrProxy proxy)
: this()
{
guidDestNet = destination;
dwParams = ConnMgrParam.GuidDestNet;
dwPriority = priority;
dwFlags = proxy;
}
public ConnMgrConnectionInfo(Guid destination, ConnMgrPriority priority)
: this(destination, priority, ConnMgrProxy.NoProxy) { }
public ConnMgrConnectionInfo(Guid destination)
: this(destination, ConnMgrPriority.UserInteractive) { }
}
与此一起的是定义来自 connmgr.h 的 C 标志的枚举
[Flags]
public enum ConnMgrParam : int
{
GuidDestNet = 0x1,
MaxCost = 0x2,
MinRcvBw = 0x4,
MaxConnLatency = 0x8
}
[Flags]
public enum ConnMgrProxy : int
{
NoProxy = 0x0,
Http = 0x1,
Wap = 0x2,
Socks4 = 0x4,
Socks5 = 0x8,
SuspendAware = 0x10,
Registered_Home = 0x20,
No_Error_Msgs = 0x40,
WakeOnIncoming = 0x80,
}
public enum ConnMgrPriority
{
UserInteractive = 0x8000,
HighPriorityBackground = 0x0200,
LowPriorityBackground = 0x0008
}
这是在连接管理器中“拨号”连接的相关 PInvoke:
[DllImport("CellCore.dll", EntryPoint = "ConnMgrEstablishConnectionSync", SetLastError = true)]
public static extern int ConnMgrEstablishConnectionSync(ConnMgrConnectionInfo connectionInfo, ref IntPtr connectionHandle,
uint dwTimeout, ref ConnMgrStatus dwStatus);
最后,这是使用正确设置实例化 ConnMgrConnectionInfo 然后从连接管理器请求连接的代码:
const string scDefaultDestinationNetwork = "My ISP";
const uint dwTimeout = 60000;
ConnMgrStatus status = ConnMgrStatus.Unknown;
IntPtr pointerOut = IntPtr.Zero;
int retVal;
if (ConnectionEntry.DestinationNetwork == null)
{
ConnectionEntry.DestinationNetwork = scDefaultDestinationNetwork;
}
Guid destinationNetworkGuid = LookupGUIDforNetwork(ConnectionEntry.DestinationNetwork);
ConnMgrConnectionInfo info = new ConnMgrConnectionInfo(destinationNetworkGuid, ConnMgrPriority.HighPriorityBackground, ConnMgrProxy.No_Error_Msgs);
retVal = Win32PInvokes.ConnMgrEstablishConnectionSync(info, ref pointerOut, dwTimeout, ref status);
if (retVal == 0)
{
ConnectionEntry.Handle = pointerOut;
ConnectionFailures = 0;
}
else
{
ConnectionFailures++;
}
此外,以下注册表设置设置为 0 以隐藏连接成功和断开连接消息:
HKEY_CURRENT_USER\ControlPanel\Notifications\{8ddf46e7-56ed-4750-9e58-afc6ce486d03}\Options (0)
HKEY_CURRENT_USER\ControlPanel\Notifications\{8ddf46e8-56ed-4750-9e58-afc6ce486d03}\Options (0)
现在,当该代码触发时,我们的信息亭样式应用程序仍然会弹出连接错误,允许用户点击设置并访问底层操作系统及其设置。
谁能看到我做错了什么?