| Цитата(0000 @ 27.6.2007, 10:47) | короче так.. вот версия коннекта, которую путем поисков в инете и мсдне удалось собрать...может кто увидит свое, знакомое - но тут ничего сугубо особенного и изощренного нет... итак... CONNMGR_CONNECTIONINFO
| Код | public unsafe class CONNMGR_CONNECTIONINFO { public int cbSize = 0x40; // Размер структуры public int dwParams = 0; // Флажки доступных полей public int dwFlags = 0; // Флажки свойств соединения public int dwPriority = 0; // Приоритет соединения public int bExclusive = 0; // Полный захват соединения приложением public int bDisabled = 0; // Соединение блокировано public Guid guidDestNet = Guid.Empty; // GUID соединения public IntPtr hWnd = IntPtr.Zero; // Окно для отображения статуса соединения public int uMsg = 0; // ID Message изменения состояния окна соединения public int lParam = 0; // lParam при сообщениях окну соединения public int ulMaxCost = 0; public int ulMinRcvBw = 0; public int ulMaxConnLatency = 0;
[DllImport("cellcore.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Winapi)] internal unsafe static extern int ConnMgrEnumDestinations(int nIndex, CONNMGR_DESTINATION_INFO pConnInfo);
[DllImport("cellcore.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Winapi)] internal unsafe static extern int ConnMgrReleaseConnection(IntPtr hConnection, int bCache);
[DllImport("cellcore.dll", CharSet = CharSet.Unicode, SetLastError = true)] internal unsafe static extern int ConnMgrEstablishConnectionSync(CONNMGR_CONNECTIONINFO pConnInfo, out IntPtr hConn, uint timeout, uint* status);
[DllImport("cellcore.dll", CharSet = CharSet.Unicode, SetLastError = true)] internal unsafe static extern int ConnMgrConnectionStatus(IntPtr hConnection, uint* status); }
|
CONNMGR_DESTINATION_INFO
| Код | public unsafe class CONNMGR_DESTINATION_INFO { public Guid guid = Guid.Empty; public char* szDescription = null; }
|
ConnMgr
| Код | public class ConnMgr { internal const int CONNMGR_PARAM_GUIDDESTNET = 0x1; // guidDestNet - доступен internal const int CONNMGR_PARAM_MAXCOST = 0x2; // ulMaxCost - доступен internal const int CONNMGR_PARAM_MINRCVBW = 0x4; // ulMinRcvBw - доступен internal const int CONNMGR_PARAM_MAXCONNLATENCY = 0x8; internal const int CONNMGR_FLAG_PROXY_HTTP = 0x1; // HTTP Proxy internal const int CONNMGR_FLAG_PROXY_WAP = 0x2; // WAP Proxy (gateway) internal const int CONNMGR_FLAG_PROXY_SOCKS4 = 0x4; // SOCKS4 Proxy internal const int CONNMGR_FLAG_PROXY_SOCKS5 = 0x8; // SOCKS5 Proxy internal const int CONNMGR_PRIORITY_VOICE = 0x20000; // Для голосового соединения internal const int CONNMGR_PRIORITY_USERINTERACTIVE = 0x08000; // Соединение актуально для пользователя internal const int CONNMGR_PRIORITY_USERBACKGROUND = 0x02000; // internal const int CONNMGR_PRIORITY_USERIDLE = 0x00800; // internal const int CONNMGR_PRIORITY_HIPRIBKGND = 0x00200; // internal const int CONNMGR_PRIORITY_IDLEBKGND = 0x00080; // internal const int CONNMGR_PRIORITY_EXTERNALINTERACTIVE = 0x00020; // internal const int CONNMGR_PRIORITY_LOWBKGND = 0x00008; // internal const int CONNMGR_PRIORITY_CACHED = 0x00002; //
// Состояние соединения internal const int CONNMGR_STATUS_UNKNOWN = 0x00; // Неизвестное состояние internal const int CONNMGR_STATUS_CONNECTED = 0x10; // Соединение есть internal const int CONNMGR_STATUS_DISCONNECTED = 0x20; // Соединение разорвано internal const int CONNMGR_STATUS_CONNECTIONFAILED = 0x21; // Соединение разорвано и не может быть востановлено internal const int CONNMGR_STATUS_CONNECTIONCANCELED = 0x22; // Пользователь разорвал соединение internal const int CONNMGR_STATUS_CONNECTIONDISABLED = 0x23; // Соединение заблокировано internal const int CONNMGR_STATUS_NOPATHTODESTINATION = 0x24; // Не найден путь доставки internal const int CONNMGR_STATUS_WAITINGFORPATH = 0x25; // Ожидание пути доставки internal const int CONNMGR_STATUS_WAITINGFORPHONE = 0x26; // Голосовой разговор internal const int CONNMGR_STATUS_WAITINGCONNECTION = 0x40; // Попытка соединения internal const int CONNMGR_STATUS_WAITINGFORRESOURCE = 0x41; // Соединение используется другой программой internal const int CONNMGR_STATUS_WAITINGFORNETWORK = 0x42; // internal const int CONNMGR_STATUS_WAITINGDISCONNECTION = 0x80; // Ожидание разрыва соединения internal const int CONNMGR_STATUS_WAITINGCONNECTIONABORT = 0x81; //
public ConnMgr() { } private static unsafe bool EnumDestinations(int nIndex, out Guid guid, out string description, out int error) { int rezult; CONNMGR_DESTINATION_INFO connMgrDestinationInfo = new CONNMGR_DESTINATION_INFO(); fixed (char* pDescription = new char[129]) //фиксируем от GC { connMgrDestinationInfo.guid = Guid.Empty; connMgrDestinationInfo.szDescription = pDescription; rezult = CONNMGR_CONNECTIONINFO.ConnMgrEnumDestinations(nIndex, connMgrDestinationInfo); error = Marshal.GetLastWin32Error(); if (rezult == 0) { guid = new Guid(connMgrDestinationInfo.guid.ToString()); description = new string(pDescription); } else { guid = Guid.Empty; description = ""; } } return (rezult == 0) ? true : false; } private static unsafe IntPtr EstablishConnection(Guid guid) { new Log().WriteLog("ConnMgr.EstablishConnection(Guid) start"); CONNMGR_CONNECTIONINFO connectionInfo = new CONNMGR_CONNECTIONINFO();
connectionInfo.cbSize = Marshal.SizeOf(connectionInfo); connectionInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET; connectionInfo.dwFlags = 0; connectionInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE; connectionInfo.bExclusive = 0; connectionInfo.bDisabled = 0; connectionInfo.guidDestNet = guid; connectionInfo.hWnd = IntPtr.Zero; connectionInfo.uMsg = 0; connectionInfo.lParam = 0; connectionInfo.ulMaxCost = 0; connectionInfo.ulMinRcvBw = 0; connectionInfo.ulMaxConnLatency = 0;
IntPtr hConnection = IntPtr.Zero; int rezult = CONNMGR_CONNECTIONINFO.ConnMgrEstablishConnection(connectionInfo, out hConnection); if (rezult != 0) new Log().WriteLog("ConnMgrEstablishConnection(Guid) failed"); else new Log().WriteLog("ConnMgr.EstablishConnection(Guid) success"); return hConnection; } public static unsafe IntPtr Connect(double timeout) { new Log().WriteLog("ConnMgr.Connect() start"); Guid guid = new Guid(); string description = ""; int error = 0; IntPtr hConnection = IntPtr.Zero; new Log().WriteLog("Internet GUID = " + guid.ToString()); bool rezult = true; while (rezult == true) { rezult = EnumDestinations(nIndex, out guid, out description, out error); new Log().WriteLog("Win32Error = " + string.Format("{0:X}", error) + " \\ " + guid.ToString() + " \\ " + description); if ((rezult) && (nIndex == 3)) { new Log().WriteLog("Internet GUID = " + guid.ToString()); hConnection = EstablishConnectionSync(guid, timeout); } nIndex++; } return hConnection; } private static unsafe IntPtr EstablishConnectionSync(Guid guid, double timeout) { CONNMGR_CONNECTIONINFO connectionInfo = new CONNMGR_CONNECTIONINFO(); connectionInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET; connectionInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE; connectionInfo.guidDestNet = guid; IntPtr hConnection = IntPtr.Zero; uint tout = (uint)(timeout * 1000 + 1); uint status = 0; int result = CONNMGR_CONNECTIONINFO.ConnMgrEstablishConnectionSync(connectionInfo, out hConnection, tout, &status); if (result != 0) new Log().WriteLog("ConnMgrEstablishConnectionSync(Guid, double) failed"); else new Log().WriteLog("ConnMgrEstablishConnectionSync(Guid, double) success"); return hConnection; } public static unsafe void ReleaseConnection(IntPtr hConnection) { new Log().WriteLog("Disconnect(IntPtr) start"); int result = CONNMGR_CONNECTIONINFO.ConnMgrReleaseConnection(hConnection, 1); if (result != 0) new Log().WriteLog("ConnMgrReleaseConnection(IntPtr) failed"); else new Log().WriteLog("ConnMgrReleaseConnection(IntPtr) success"); }
private static unsafe Guid GuidConnection(int nIndex) { new Log().WriteLog("GuidConnection(int) start"); Guid guid = Guid.Empty; CONNMGR_DESTINATION_INFO connMgrDestinationInfo = new CONNMGR_DESTINATION_INFO(); fixed (char* pDescription = new char[129]) { connMgrDestinationInfo.szDescription = pDescription; if (CONNMGR_CONNECTIONINFO.ConnMgrEnumDestinations(nIndex, connMgrDestinationInfo) == 0) { guid = new Guid(connMgrDestinationInfo.guid.ToString()); new Log().WriteLog("GuidConnection(int) success"); } else new Log().WriteLog("GuidConnection(int) failed"); } return guid; } }
|
тут еще приведены куча констант состояния подключения - их тоже можно использовать уже кому как нравится, поэтому реализацию какую-нибудь я сюда не приводил...так что вот.... если кому понадобится - берите..и спасибо всем, кто помог с эти мне на разных форумах!!! |
Не работает и не полный код! |