TCP通信,指定 SOCK_STREAM 套接字
接收字符串的时候会有时出现乱码,为何?
数据接收是没问题,没有出现 SOCKET_ERRORtypedef struct
{
char chPath[MAX_PATH+4];
int bTypeFile;
DWORD nfileSize;
}SendInfo;如上结构接收,提取 chPath,断点处 发现 chPath 时而会出现乱码,有没有办法可以判断的?
接收字符串的时候会有时出现乱码,为何?
数据接收是没问题,没有出现 SOCKET_ERRORtypedef struct
{
char chPath[MAX_PATH+4];
int bTypeFile;
DWORD nfileSize;
}SendInfo;如上结构接收,提取 chPath,断点处 发现 chPath 时而会出现乱码,有没有办法可以判断的?
字符串,
//the Watch window.brw,When browsing//怀疑是网页的东西但是问题还是存在,乱码还是存在,或者么接收过来的全部为空
buffer要养成清0的好习惯:memset(buffer, 0 ,buffer_len);
MyTransFolder\MyTransFolderDlg.cpp(466) 附近,
MyTransFolder\MyTransFolderDlg.cpp(593) 附近,
这两处有SendInfo info,但没问题。发现有一处问题:CString::GetBuffer()调用后,一定要调用CString::GetBuffer();见MSDN描述:
CString::GetBuffer
LPTSTR GetBuffer( int nMinBufLength );
throw( CMemoryException );Return ValueAn LPTSTR pointer to the object’s (null-terminated) character buffer.ParametersnMinBufLengthThe minimum size of the character buffer in characters. This value does not include space for a null terminator.ResReturns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents.If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions. The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CString operations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.The buffer memory will be freed automatically when the CString object is destroyed. Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 for the length to ReleaseBuffer and ReleaseBuffer will perform a strlen on the buffer to determine its length. ExampleThe following example demonstrates the use of CString::GetBuffer.// example for CString::GetBuffer
CString s( "abcd" );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
LPTSTR p = s.GetBuffer( 10 );
strcpy( p, "Hello" ); // directly access CString buffer
s.ReleaseBuffer( );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif