Ask more, WINDOWSCE programming 99% of the problem is related to Unicode. For example, file editing, generally saved as an ANSI format; wireless communication controls the AT command to send by MODEM, must be an ASI format; network communication, PC terminal All ANSI, in order to be compatible with the PC, you must convert one instruction to be sent from Unicode to ANSI format from Unicode ... Wait. Many beginners are always very troublesome. In fact, there are Windows Ce. The standard API implements the interaction between Unicode and ANSI characters. Below is the program block in the network communication.
m_psocket is a class derived from cccesocket. If it is not connected, it is null; m_snd is the cstring to be sent, and one Edit corresponds.
// Send function segment void cclient1dlg :: onButtonsend () {// Todo: add your control notification handler code here if (! M_psocket) // No socket connection, exit {MessageBox (Text ("no connection!"), Text "Information")); Return;} Updatedata (TRUE); // Save the input string to m_snd unsigned char buf [129]; // Send buffer ZeromeMory (buf, sizeof (buf)); // buffer clear Zero CSTRING TMPSTR (m_snd); // Copy the string INT multus INT multus = widechartomultibyte (// calculate the number of bytes required from Unicode to ANSI) CP_ACP, // According to ANSI Code Page | WC_DEFAULTCHAR, / / Conversion Error uses default characters instead of tmpstr.getbuffer (m_snd.getLength ()), // To convert the string address m_snd.getlength (), // to convert the number of 0, // Convert 0 After converting the address 0 , // The number of most converted characters, indicates how many bytes 0, // default characters after returning to convert Unicode: "/ 0" 0 // default setting); WideChartomultibyte (// Convert Unicode Go to ANSI CP_ACP, WC_CompositeCHECK | WC_DEFAULTCHAR, TMPSTR.GETBUFFER (m_snd.getLength ()), m_snd.getlength (), (char *) buf, // Convert to buffer 128, // up to 128 bytes 0, 0 ); Int sendcount = m_psocket-> send (buf, multibytelen 1); // Send conversion-converted buffer cstring statusStr; StatusStr.Format (Text ("total number of bytes:% D"), sendcount); m_status .SETWINDOWTEXT ( STATUSSTR); // Update Display Bar}
The string received by the program is finally saved to the CString Tmpstr.
// Receive Function Pieces Void Mycesocket :: OnRecEates (int Nerror) {// Todo: add your specialized code here and / or call the base class unsigned char p [129]; // Accept buffer ZeromeMory (p, sizeof )); // Receive buffer clear this-> receive (p, 128); // receive 128 bytes int widecharlen = multibytetowideChar (// calculate the number of bytes required from ANSI to Unicode) CP_ACP, MB_composite, (CHAR *) P, // To convert the ANSI string -1, // automatic calculation length 0, 0); CSTRING TMPSTR; TMPSTR.GETBUFFER (WideCharlen); / / Save the Unicode string after the conversion Allocation MultibyToDechar ( // Switch from ANSI to Unicode Character CP_ACP, MB_ComposTr.getBuffer (WideCharlen), // Convert to TMPSTR WideCharlen // Transfer WideCharlen Unicode Character); m_clientdlg-> m_listbox.insertstring (0, TMPSTR); // Insert Ccesocket :: OnReceive (NERRORCODE) in the ListBox;
Note: The above code is running on the WindowsCe model machine, and the PC side sends and receive characters are ANSI format. Slightly modified the above code, use the previous protocol to seamlessly connect the PDA and PC. The above code is in Microsoft Embed Visual C 3.0 Lenovo Tianzhu 5100 (Windowsce 3.0) Eagle Tec 10M CF card passed .2003.Feb.18th, 5: 25 pmroving in shenzhen ...