注册 登录
编程论坛 VC++/MFC

用sendto发送十六进制数组的问题,请教??

kxywnljz 发布于 2011-03-25 09:45, 1550 次点击
开始是这样的:
         CString strSend;
    GetDlgItemText(IDC_EDIT_SEND,strSend);
    sendto(m_socket,strSend,strSend.GetLength()+1,0,
    (SOCKADDR*)&addrTo,sizeof(SOCKADDR));
我改为这样的,如下:

BYTE buffer[] = { 0x23, 0x1A, 0x00, 0x00, 0x00, 0xCC, 0xC4, 0x14, 0x00, 0x0A, 0x40, 0xC5, 0x00, 0xD9, 0xE4, 0x22, 0x33, 0x1F, 0x98, 0x7C};
sendto( SOCKET, buffer, sizeof(buffer), 0);
SetDlgItemText(IDC_EDIT_SEND,"");

编译出现如下错误????
Compiling...
ChatDlg.cpp
C:\Documents and Settings\Administrator\桌面\Chat\ChatDlg.cpp(254) : error C2275: 'SOCKET' : illegal use of this type as an expression
        c:\program files\microsoft visual studio\vc98\include\winsock.h(35) : see declaration of 'SOCKET'
Error executing cl.exe.

ChatDlg.obj - 1 error(s), 0 warning(s)

请大侠指点,或有什么好方法呢??
3 回复
#2
debroa7232011-03-25 20:48
sendto的第一个参数从前文看是一个SOCKET对象,而你使用了一个命名,这是语法问题.你需要创建一个SOCKET对象然后再做为参数传进sendto函数中.
#3
kxywnljz2011-03-28 10:02
用sendto发送十六进制数组的问题,请教??
开始是这样的:
         CString strSend;
    GetDlgItemText(IDC_EDIT_SEND,strSend);
    sendto(m_socket,strSend,strSend.GetLength()+1,0,
    (SOCKADDR*)&addrTo,sizeof(SOCKADDR));
我改为这样的,如下:

BYTE buffer[] = { 0x23, 0x1A, 0x00, 0x00, 0x00, 0xCC, 0xC4, 0x14, 0x00, 0x0A, 0x40, 0xC5, 0x00, 0xD9, 0xE4, 0x22, 0x33, 0x1F, 0x98, 0x7C};
sendto(m_socket, buffer, sizeof(buffer), 0,(SOCKADDR*)&addrTo,sizeof(SOCKADDR));
SetDlgItemText(IDC_EDIT_SEND,"");
编译出现如下错误????
--------------------Configuration: Chat - Win32 Debug--------------------
Compiling...
ChatDlg.cpp
C:\Documents and Settings\Administrator\桌面\Chat\ChatDlg.cpp(255) : error C2664: 'sendto' : cannot convert parameter 2 from 'unsigned char [20]' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.请大侠指点,或有什么好方法呢??
我知道sendto(),原函数中用的是'const char *,而我用的是unsigned char 即BYTE buffer,这个怎么改呢?我要用16进制发送啊????
#4
debroa7232011-04-12 22:44
类型显示强转第二个参数  (char*)
1