MY NOTE 2010/10 N3
3.UpdateData(TRUE) 与UpdateData(FALSE)的区别 -UpdateData(TRUE) 从窗口中获得数据,更新到空间变量 -UpdateData(FALSE) 给空间变量赋值后,更新到窗口中可见
4.双字节转换为单字节 与 单字节转换为双字节 【双字节转换为单字节1】 -char ansiRemoteHost[255]; //单字节 ZeroMemory(ansiRemoteHost,255); //初始化 WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK, m_remoteHost,wcslen(m_remoteHost) ,ansiRemoteHost,wcslen(m_remoteHost), NULL,NULL); //[CString] m_remoteHost //[char] ansiRemoteHost // 长度统一: 以双字符长度为标准 【双字节转换为单字节2】 - TCHAR *wBuff = new TCHAR[256]; char *Buff = new char[256*2]; memset(Buff,'\0',256); memset(wBuff,'\0',256); wBuff = _T("Hello World!"); wcstombs(Buff, wBuff, 256);
【单字节转换为双字节】 -char *Buff = new char[256]; TCHAR *wBuff = new TCHAR[256]; memset(Buff,'\0',256); memset(wBuff,'\0',256); Buff = "Hello World!"; mbstowcs(wBuff, Buff, 256);
5.socket通信[异步模式] 和 [同步模式]设置 -DWORD ul = 1; ioctlsocket(m_socket,FIONBIO,&ul);
6.wm端接受part处理 -构建while无限循环,由事件引导读取操作 -检测退出事件,检测有读事件,错误事件 【select函数 winsocket】 =》This function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O. int select( int nfds, fd_set FAR* readfds, fd_set FAR* writefds, fd_set FAR* exceptfds, const struct timeval FAR* timeout );
【fd_set Structure】 The fd_set structure is used by various Windows Sockets functions and service providers, such as the select function, to place sockets into a "set" for various purposes, such as testing a given socket for readability using the readfds parameter of the select function.
typedef struct fd_set { u_int fd_count; SOCKET fd_array[FD_SETSIZE]; } fd_set;
7. 判断socket是否可读(是否有数据到来) 1.定义读事件集合,fd_set fdRead; 以及TIMEVAL aTime 2.置空fdRead, FD_ZERO(&fdRead); 3.给socket设置读事件,int ret = select(0,&fdRead,NULL,NULL,aTime); 当ret == SOCKET_ERROR, (可能连接已断开造成)触发错误事件,断开连接; 当ret > 0 ,(表明连接有效) 进行判断是否可读 -if( FD_ISSET(m_socket,&fdRead) ) |