Windows ce gprs dialing program)

Source: Internet
Author: User
#include "stdafx.h" #include "ras.h" HANDLE hPort = INVALID_HANDLE_VALUE; HRASCONN hRasConn = NULL; BOOL CreatePort() {     DWORD dwNumBytesWritten;     BOOL fRet;     BYTE Bytes[]={'A','T','+','C','G','D','C','O','N','T','=','1',',','"','I','P','"',',',
'"', 'C', 'M', 'n', 'E', 't', '"', 0x0D, 'A','t ', 'D ', 't',' * ', '9', '9',' # ', 0x0D }; // open the serial port hPort = CreateFile (TEXT ("COM8:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hPort = INVALID_HANDLE_VALUE) {// cocould not open the port. // printf ("Open the serial port failed \ n \ r"); return FALSE;} // BYTE Bytes [] = {'A', 't', 0x0D }; // DWORD CgdcontSize = sizeof (Cgdcont); DWORD BytesSize = Sizeof (Bytes); // fRet = WriteFile (hPort, Cgdcont, CgdcontSize, & signature, NULL); fRet = WriteFile (hPort, Bytes, BytesSize, & dwNumBytesWritten, NULL ); fRet = ReadFile (hPort, Bytes, 4, & dwNumBytesWritten, NULL); if (fRet) {// printf ("open the serial port successful \ n \ r "); closeHandle (hPort);} else {// close the serial port CloseHandle (hPort); // printf ("Close serial port successful \ n \ r");} return TRUE;} lresult callback WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {RASCONNSTATE RasState = (RASCONNSTATE) wParam; switch (Msg) {case when: switch (RasState) {case RASCS_OpenPort: printf ("opening port \ n \ r"); break; case RASCS_PortOpened: printf ("port opened \ n \ r"); break; case RASCS_ConnectDevice: printf ("Connecting Device \ n \ r"); break; case RASCS_Connected: // int I; // printf ("connected \ n \ r"); // s Canf ("% d", I); // if (I = 1) // {// RasHangUp (hRasConn); //} break; case RASCS_Disconnected: printf ("disconnected \ n \ r"); break; default: printf ("unknown \ n \ r"); break;} break; default: return DefWindowProc (hWnd, msg, wParam, lParam);} return TRUE;} int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {// TODO: Place code here. HWND hwnd; MSG msg; WNDCLASS wc; wc. sty Le = 0; wc. lpfnWndProc = (WNDPROC) WndProc; wc. cbClsExtra = 0; wc. cbWndExtra = 0; wc. hInstance = hInstance; wc. hIcon = 0; wc. hCursor = 0; wc. hbrBackground = NULL; wc. lpszMenuName = 0; wc. lpszClassName = _ T ("embo"); RegisterClass (& wc); hwnd = CreateWindow (_ T ("embo"), _ T ("EmboConnection"), 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, 0); CreatePort (); RASDIALPARAMS rdParams; // dialing parameter // initialize the dialing parameter rdP Arams. dwSize = sizeof (RASDIALPARAMSW); wcscpy (rdParams. szEntryName, _ T ("Embo Connection"); wcscpy (rdParams. szPhoneNumber, _ T (""); wcscpy (rdParams. szCallbackNumber, _ T (""); wcscpy (rdParams. szUserName, _ T (""); wcscpy (rdParams. szPassword, _ T (""); wcscpy (rdParams. szDomain, _ T (""); DWORD dwRet; // dial-up connection // printf ("connecting \ n \ r"); dwRet = RasDial (NULL, NULL, & rdParams, 0 xFFFFFFFF, hwnd, & hRasConn); if (dwRet! = 0) // connection successful {RasHangUp (hRasConn);} while (GetMessage (& msg, NULL, 0, 0 )! = FALSE) {TranslateMessage (& msg); DispatchMessage (& msg);} return 0 ;}

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.