windows ce gprs 撥號程式)

來源:互聯網
上載者: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 )     {         // Could 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, &dwNumBytesWritten,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 WM_RASDIALEVENT:         switch(RasState)         {         case RASCS_OpenPort:             printf("正在開啟連接埠\n\r");             break;         case RASCS_PortOpened:             printf("連接埠已經開啟\n\r");             break;         case RASCS_ConnectDevice:             printf("正在串連裝置\n\r");             break;         case RASCS_Connected:             //int i;             //printf("已串連\n\r");             //scanf("%d",i);             //if(i==1)             //{             // RasHangUp(hRasConn);             //}             break;         case RASCS_Disconnected:             printf("串連已斷開\n\r");             break;         default:             printf("未知\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.style = 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;//撥號參數    //初始化撥號參數    rdParams.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;     //撥號連線    //printf("connecting  \n\r");     dwRet = RasDial(NULL,NULL,&rdParams,0xFFFFFFFF,hwnd ,&hRasConn);     if(dwRet != 0)//connection successful     {         RasHangUp(hRasConn);     }     while ( GetMessage(&msg, NULL, 0, 0) != FALSE )     {         TranslateMessage(&msg);         DispatchMessage(&msg);     }     return 0; } 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.