Click here to Skip to main content
16,003,462 members
Home / Discussions / Mobile
   

Mobile

 
AnswerRe: what is Symbian OS? Pin
CJCraft.com13-Feb-04 9:32
CJCraft.com13-Feb-04 9:32 
GeneralRe: what is Symbian OS? Pin
bensoncd14-Feb-04 2:17
bensoncd14-Feb-04 2:17 
GeneralDebugging only works if connected to Network Pin
camasmartin4-Feb-04 7:46
camasmartin4-Feb-04 7:46 
GeneralRe: Debugging only works if connected to Network Pin
João Paulo Figueira4-Feb-04 22:08
professionalJoão Paulo Figueira4-Feb-04 22:08 
GeneralRe: Debugging only works if connected to Network Pin
camasmartin16-Feb-04 9:21
camasmartin16-Feb-04 9:21 
Generaljava in embedded world Pin
Anonymous4-Feb-04 4:13
Anonymous4-Feb-04 4:13 
GeneralRemoving links from the start menu Pin
KellyR3-Feb-04 7:57
KellyR3-Feb-04 7:57 
GeneralConnectionManager from .NET Compact Framework Pin
Jonkr3-Feb-04 1:35
Jonkr3-Feb-04 1:35 
I am working on an application for the Intermec 740 (PocketPC 2002), written in C# under .NET Compact Framework. I want to establish a GPRS connection to the internet via a bluetooth mobilephone using "ConnectionManager".

I need to make a call to "ConnectionManager" in the dll "cellcore.dll", i.e. a call to unmanaged code which need marshaling of the data structures.

I have included the code below.

When I run the code, I loose the connection to the Intermec completely, so it is pretty difficult for me to debug this code.
But I think the problem is around the marshaling of the data structures used as parameters to the functions in "cellcore.dll".

Have anyone successfully used the ConnectionManager from .NET Compact Framework (C#) ?

Does anyone have ideas how to proceed from here, e.g. experience with calls to unmanaged code and marshaling of structs from C# ?


using System;using System.Collections;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace Mobile.ConnectionManager<br />
{<br />
	public class ConnMgr<br />
	{<br />
		private const int CONNMGR_PARAM_GUIDDESTNET        = 0x1;<br />
		private const int CONNMGR_PARAM_MAXCOST            = 0x2;<br />
		private const int CONNMGR_PARAM_MINRCVBW           = 0x4;<br />
		private const int CONNMGR_PARAM_MAXCONNLATENCY     = 0x8;<br />
<br />
		private const int CONNMGR_PRIORITY_USERINTERACTIVE = 0x08000;<br />
		<br />
		//typedef struct _CONNMGR_DESTINATION_INFO <br />
		//	{<br />
		//	  GUID guid;<br />
		//	  TCHAR szDescription[CONNMGR_MAX_DESC];<br />
		//	} CONNMGR_DESTINATION_INFO;<br />
<br />
		public unsafe class CONNMGR_DESTINATION_INFO<br />
		{<br />
			public Guid   guid          = Guid.Empty;<br />
			public char*  szDescription = null;<br />
		}<br />
<br />
		//typedef struct _CONNMGR_CONNECTIONINFO <br />
		//		{<br />
		//			DWORD cbSize;<br />
		//			DWORD dwParams;<br />
		//			DWORD dwFlags;<br />
		//			DWORD dwPriority;<br />
		//			BOOL bExclusive;<br />
		//			BOOL bDisabled;<br />
		//			GUID guidDestNet;<br />
		//			HWND hWnd;<br />
		//			UINT uMsg;<br />
		//			LPARAM lParam;<br />
		//			ULONG ulMaxCost;<br />
		//			ULONG ulMinRcvBw;<br />
		//			ULONG ulMaxConnLatency;<br />
		//		} CONNMGR_CONNECTIONINFO;<br />
<br />
		public unsafe class CONNMGR_CONNECTIONINFO<br />
		{<br />
			public int    cbSize;<br />
			public int    dwParams;<br />
			public int    dwFlags;<br />
			public int    dwPriority;<br />
			public bool   bExclusive;<br />
			public bool   bDisabled;<br />
			public Guid   guidDestNet;<br />
			public IntPtr hWnd;<br />
			public int    uMsg;<br />
			public int    lParam;<br />
			public int    ulMaxCost;<br />
			public int    ulMinRcvBw;<br />
			public int    ulMaxConnLatency;<br />
		}<br />
<br />
		[DllImport("cellcore.dll", SetLastError=true)]<br />
		private unsafe static extern int ConnMgrEnumDestinations(<br />
			int                      nIndex,<br />
			CONNMGR_DESTINATION_INFO destinationInfo<br />
			);<br />
<br />
		[DllImport("cellcore.dll", SetLastError=true)]<br />
		private unsafe static extern IntPtr ConnMgrEstablishConnection(<br />
			CONNMGR_CONNECTIONINFO pConnInfo<br />
			);<br />
<br />
		public ConnMgr()<br />
		{<br />
		}<br />
<br />
		public static unsafe bool EnumDestinations(int nIndex, out Guid guid, out string description, out int error)<br />
		{<br />
			int result;<br />
<br />
			CONNMGR_DESTINATION_INFO connMgrDestinationInfo = new CONNMGR_DESTINATION_INFO();<br />
<br />
			fixed (char* pDescription = new char[129])<br />
			{<br />
				connMgrDestinationInfo.guid          = Guid.Empty;<br />
				connMgrDestinationInfo.szDescription = pDescription;<br />
<br />
				result = ConnMgrEnumDestinations(nIndex, connMgrDestinationInfo);<br />
<br />
				error  = Marshal.GetLastWin32Error();<br />
<br />
				if (result == 0)<br />
				{<br />
					guid        = new Guid(connMgrDestinationInfo.guid.ToString());<br />
					description = new string(pDescription);<br />
				}<br />
				else<br />
				{<br />
					guid        = Guid.Empty;<br />
					description = "";<br />
				}<br />
			}<br />
<br />
			return (result == 0) ? true : false;<br />
		}<br />
<br />
		public static unsafe IntPtr EstablishConnection (Guid guid)<br />
		{<br />
			CONNMGR_CONNECTIONINFO connectionInfo = new CONNMGR_CONNECTIONINFO();<br />
			<br />
			connectionInfo.cbSize           = Marshal.SizeOf(connectionInfo);<br />
			connectionInfo.dwParams         = CONNMGR_PARAM_GUIDDESTNET;<br />
			connectionInfo.dwFlags          = 0;<br />
			connectionInfo.dwPriority       = CONNMGR_PRIORITY_USERINTERACTIVE;<br />
			connectionInfo.bExclusive       = false;<br />
			connectionInfo.bDisabled        = false;<br />
			connectionInfo.guidDestNet      = guid;<br />
			connectionInfo.hWnd             = IntPtr.Zero;<br />
			connectionInfo.uMsg             = 0;<br />
			connectionInfo.lParam           = 0;<br />
			connectionInfo.ulMaxCost        = 0;<br />
			connectionInfo.ulMinRcvBw       = 0;<br />
			connectionInfo.ulMaxConnLatency = 0;<br />
<br />
			return ConnMgrEstablishConnection(connectionInfo); // At this point I loose the connection to the Intermec<br />
		}<br />
	}<br />
}



Test function:

		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			int    nIndex      = 0;<br />
			Guid   guid        = new Guid();<br />
			string description = "";<br />
			int    error       = 0;<br />
			bool   result      = true;<br />
<br />
			textBox1.Text = "";<br />
<br />
			while (result == true)<br />
			{<br />
				result = ConnMgr.EnumDestinations(nIndex, out guid, out description, out error);<br />
<br />
				textBox1.Text += "Win32Error = " + string.Format("{0:X}", error) + "\r\n" +<br />
					guid.ToString() + "\r\n" +<br />
					description + "\r\n";<br />
<br />
				if ((result == true) && (nIndex == 4))<br />
				{<br />
					// This is the internet connection<br />
					ConnMgr.EstablishConnection(guid);<br />
				}<br />
<br />
				nIndex++;<br />
			}<br />
		}

GeneralOnDraw() in a View Pin
cberam3-Feb-04 1:10
cberam3-Feb-04 1:10 
GeneralTooltips on added MFC toolbars (PPC2003) Pin
LunaticFringe2-Feb-04 17:01
LunaticFringe2-Feb-04 17:01 
GeneralRe: Tooltips on added MFC toolbars (PPC2003) Pin
João Paulo Figueira2-Feb-04 22:52
professionalJoão Paulo Figueira2-Feb-04 22:52 
GeneralRe: Tooltips on added MFC toolbars (PPC2003) Pin
LunaticFringe3-Feb-04 7:24
LunaticFringe3-Feb-04 7:24 
Generalrun same program on PPC3.0 and PPC4.2 Pin
slomoman2-Feb-04 3:19
slomoman2-Feb-04 3:19 
GeneralRe: run same program on PPC3.0 and PPC4.2 Pin
João Paulo Figueira2-Feb-04 5:17
professionalJoão Paulo Figueira2-Feb-04 5:17 
GeneralRe: run same program on PPC3.0 and PPC4.2 Pin
slomoman2-Feb-04 6:10
slomoman2-Feb-04 6:10 
GeneralAdding method via Classwizard Pin
misha_grewal31-Jan-04 19:18
misha_grewal31-Jan-04 19:18 
GeneralRe: Adding method via Classwizard Pin
João Paulo Figueira1-Feb-04 22:57
professionalJoão Paulo Figueira1-Feb-04 22:57 
GeneralProblem with CFormView in Doc/View-Application (eVC4/MFC) Pin
Ralf Limbacher30-Jan-04 6:30
sussRalf Limbacher30-Jan-04 6:30 
GeneralThere is a hard problem about pdb format Pin
lsaturn29-Jan-04 18:41
lsaturn29-Jan-04 18:41 
GeneralStrange problem when writing to a file Pin
Cedric Moonen27-Jan-04 23:37
Cedric Moonen27-Jan-04 23:37 
GeneralRe: Strange problem when writing to a file Pin
João Paulo Figueira28-Jan-04 4:08
professionalJoão Paulo Figueira28-Jan-04 4:08 
GeneralRe: Strange problem when writing to a file Pin
Cedric Moonen28-Jan-04 4:18
Cedric Moonen28-Jan-04 4:18 
GeneralRe: Strange problem when writing to a file Pin
João Paulo Figueira28-Jan-04 4:24
professionalJoão Paulo Figueira28-Jan-04 4:24 
GeneralRe: Strange problem when writing to a file Pin
Cedric Moonen28-Jan-04 4:45
Cedric Moonen28-Jan-04 4:45 
GeneralSymbian / Series 60 development Pin
Antti Keskinen27-Jan-04 8:15
Antti Keskinen27-Jan-04 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.