我收到了这个警告
warning C4309: 'initializing' : truncation of constant value
当我尝试执行我的dll时,它只发送4个字节而不是10个字节。
可能出了什么问题?
这是我的代码:
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
cout << "[SEND:" << len << "] ";
for ( int i = 0; i < len; i++ ) {
printf( "%02x ", static_cast<unsigned char>( buf[i] ) );
}
printf("\n");
//causing the warning:
char storagepkt[] = {0x0A, 0x00, 0x01, 0x40, 0x79, 0xEA, 0x60, 0x1D, 0x6B, 0x3E};
buf = storagepkt;
len = sizeof(storagepkt);
return pSend(s, buf, len, flags);
}
更新
int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags);
更新
根据建议,我尝试了memcpy:
memcpy((char*) buf, storagepkt, sizeof(storagepkt));
更新
unsigned char storagepkt[] = {0x0A, 0x00, 0x01, 0x40, 0x79, 0xEA, 0x60, 0x1D, 0x6B, 0x3E};
已经修复。
pSend()
,但是没有提供该函数。相反提供的是MySend()
。这是一个拼写错误还是缺少某些内容? - wallykbuf
是一个指针。buf = storagepkt
会覆盖函数参数。也许你想要将storagepkt
的内容复制到buf
中?如果是这样,请查找memcpy
。 - John Dvorak