C # For GPRS and CDMA development in Windows Mobile)

Source: Internet
Author: User

For GPRS and CDMA DevelopmentArticleThere are already a lot of online connections, but the GPRS and CDMA connection libraries provided by the Windows Mobile SDK only support the C ++ version (that is, the Connection Manager API ), most of the articles on the Internet are in C ++. Although C # is also written, most of the packages are incorrect and have not been well tested, this article describes how to use C # For GPRS and CDMA development on existing network materials.

References:

Http://www.vckbase.com/document/viewdoc? Id = 1803

Http://www.cnblogs.com/jsjkandy/archive/2008/08/06/1262445.html

Http://blogs.msdn.com/anthonywong/archive/2006/03/13/550686.aspx

Development Environment

Visual Studio 2005

Windows Mobile 6 SDK professional

Header file Encapsulation

We need to use a C ++ header file connmgr of Windows Mobile SDK. h. The path is c: \ Program Files \ Windows Mobile 6 SDK \ pocketpc \ include \ armv4i \ connmgr. h. First, use C # to redefine the constants, structures, and external function declarations of the header file to be used.

For more instructions on C # platform mail, refer to msdn:

Http://msdn.microsoft.com/zh-cn/library/fzhhdwae (vs.80). aspx

Constant declaration:

[Code = C # ] Const int S_ OK = 0; Const Uint connmgr_param_guiddestnet = 0x1; Const Uint connmgr_priority_userinteractive = 0x08000; Const Uint infinite = 0 xffffffff; Const Uint connmgr_status_connected = 0x10; Const int Connmgr_max_desc = 128; // @ Constdefine Max size of a Network Description  Const int Connmgr_flag_proxy_http = 0x1;// @ Constdefine HTTP Proxy supported  Const int Connmgr_flag_proxy_wap = 0x2; // @ Constdefine WAP proxy (GATEWAY) supported  Const int Connmgr_flag_proxy_socks4 = 0x4; // @ Constdefine socks4 proxy supported  Const int Connmgr_flag_proxy_socks5 = 0x8; // @ Constdefine SOCKS5 Proxy supported  Const Uint16 idc_wait = 32514; Const Uint16 idc_arrow = 32512; [/Code]

Structure mail Declaration:

C ++Prototype:

[Code = C ++] Typedef struct _ Connmgr_connectioninfo {DWORD cbsize; // @ Field size of this structure DWORD dwparams; // @ Field valid parms, set of connmgr_param _* DWORD dwflags; // @ Field connection flags, set of connmgr_flag _* DWORD dwpriority; // @ Field priority, one of connmgr_priority _* Bool bexclusive; // @ Field connection is exclusive, see comments Bool bdisabled; // @ Field don't actually connect Guid guiddestnet; // @ Field guid of network to connect Hwnd; // @ Field hwnd to post status change messages Uint umsg; // @ Field MSG to use when posting status changes Lparam; // @ Field lparam to use when posting status changes Ulong ulmaxcost; // @ Field Max acceptable cost of connection Ulong ulminrcvbw; // @ Field min acceptable receive bandwidth of Connection Ulong ulmaxconnlatency; // @ Field Max acceptable connect latency } Connmgr_connectioninfo; Typedef struct _ Connmgr_destination_info {guid; // @ Field guid associated with network Tchar szdescription [connmgr_max_desc]; // @ Field description of Network Bool fsecure; // @ Field is it OK to allow multi-homing on the network } Connmgr_destination_info; Typedef struct _ Guid { // Size is 16 DWORD data1; Word data2; Word data3; byte data4 [8] ;}guid; [/Code]

C #Statement

[Code = C # ] [Structlayout (layoutkind. Sequential)] Public struct Connmgr_connectioninfo { Public Uint cbsize; Public Uint dwparams; Public Uint dwflags; Public Uint dwpriority; Public int Bexclusive; Public int Bdisabled; Public Guid guiddestnet; Public Intptr hwnd; Public Uint umsg; Public Uint lparam;Public Uint ulmaxcost; Public Uint ulminrcvbw; Public Uint ulmaxconnlatency;} [structlayout (layoutkind. Sequential, charset = charset. Unicode)] Public struct Connmgr_destination_info { Public Guid; // @ Field guid associated with network [Financialas (unmanagedtype. byvaltstr, sizeconst = connmgr_max_desc)] Public String szdescription; // @ Field description of Network Public int Fsecure; // @ Field is it OK to allow multi-homing on the network } Public struct Guid { // Size is 16  Public Uint data1; Public Uint16 data2; Public Uint16 data3; [financialas (unmanagedtype. byvalarray, sizeconst = 8)] Public Byte [] data4;} [/Code]

 

Function mail Declaration:

C ++ prototype:

See connmgr. h

C # statement:

[Code = C # ] [Dllimport ("Coredll. dll" )] Public static extern Uint gettickcount (); [dllimport ( "Coredll. dll" )] Public static extern Uint waitforsingleobject (intptr hhandle, uint dwmilliseconds); [dllimport ( "Cellcore. dll" )] Public static extern int Connmgrmapurl (string pwszurl, ref guid pguid, ref uint pdwindex); [dllimport ( "Cellcore. dll" )] Public static extern int Connmgrestablishconnectionsync (ref connmgr_connectioninfo CI, ref intptr phconnection, uint dwtimeout, ref uint pdwstatus); [dllimport ( "Cellcore. dll" )] Private Static extern Intptr connmgrapireadyevent (); [dllimport ( "Cellcore. dll" )] Public static extern int Connmgrreleaseconnection (intptr hconnection, Int Bcache); [dllimport ( "Cellcore. dll" )] Public static extern int Connmgrenumdestinations ( Int Nindex, ref connmgr_destination_info pdestinfo); [dllimport ( "Cellcore. dll" )] Public static extern int Connmgrconnectionstatus (intptr hconnection, ref uint pdwstatus );  [Dllimport ( "Coredll. dll" )] Private Static extern int Closehandle (intptr hobject); [/Code]

See http://www.vckbase.com/document/viewdoc/ here? The id = 1803 example uses C # To encapsulate a class library and implement a similar demo. Shows the running interface:

In the demo, add a demonstration of establishing GPRS and establishing CDMA connections,Code:

[Code = C # ] ///  <Summary>  /// Connect to the mobile network ///  </Summary>  ///  <Returns> </returns>  Private Static bool Connectmobilenetwork (string csdesc) {connectmanager = New Connectmanager (); List <connectmanager. connmgr_destination_info> lst = connectmanager. enumnetidentifier (); Int Nindex = 0; // Select connection  For (; Nindex <lst. Count; nindex ++ ){ If (String. Compare (LST [nindex]. szdescription, csdesc, True ) = 0 ){ Break ;}} // Establish a connection If (Nindex> = 0 & nindex <lst. Count ){ Return Connectmanager. establishconnection (uint) nindex );} Return false ;} ///  <Summary>  /// Establish a GPRS connection ///  </Summary>  ///  <Param name = "sender"> </param>  ///  <Param name = "E"> </param>  Private void Btnconnectupls_click (Object sender, eventargs e ){ If (! Connectmobilenetwork ( "Internet Settings" ) {MessageBox. Show ( "Unable to establish GPRS connection! " ); Return ;} Else {MessageBox. Show ( "The GPRS connection is established successfully! " );}} ///  <Summary>  /// Establish a CDMA connection ///  </Summary> ///  <Param name = "sender"> </param>  ///  <Param name = "E"> </param>  Private void Btnconnectcdma _click (Object sender, eventargs e ){ If (! Connectmobilenetwork ( "China Unicom WAP" ) {MessageBox. Show ( "Unable to establish CDMA connection! " ); Return ;} Else {MessageBox. Show ("The CDMA connection is established successfully! " ) ;}} [/Code]

 Mobile phone settings

The following describes how to set the GPRS connection. Most mobile phones can use the default settings directly and do not use their own settings. However, if you find that the above Code cannot establish a GPRS connection after running, test the following settings.

In the above GPRS connection code, we use the "Internet Settings" setting. If the phone has not set this connection or already set up, the connection always fails, you can set up or modify the connection settings as follows (here the Windows Mobile 5 Operating System, the Mobile SIM card, and the simulator are used ):

1. Open "start-> Settings" and click "Connect ".

2. if your mobile phone already has Internet settings, there will be a "manage existing connections" link in Figure 2. Click it to modify the settings, click "Add new modem connection" here to add an Internet setting.

3. In the dialog box shown in 3, select the modem as "GPRS )".

4. In the displayed Dialog Box 4, enter "cmnet" for "Access Point name ".

5. In the displayed dialog box 5, click "finish ". For a private network, enter the username and password provided by mobile.

6. click "finish" and add "GRPS connection to Internet" in "Internet Settings". If there are several settings, make sure that the settings you want to use are selected. Click "OK" to exit the settings. In this case, you can use the instanceProgramTo try the connection. During the connection, do not synchronize the phone with the computer; otherwise, the phone may not be dialing.

From the above usage, we can know that the difference between establishing a GPRS connection and establishing a CDMA connection is only the difference between the connection settings, that is, the dialing problem. However, many people on the internet ask questions about GPRS development and CDMA development. Here we use this demo, hoping to provide some help to those who want to learn mobile development.

Source code download: http://download.csdn.net/source/1047113

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.