【发布时间】:2019-12-02 01:58:21
【问题描述】:
这段代码是在 Borland C++Builder 6 中使用 Indy 9 编写的:
void __fastcall TfrmMain::ServerConnect(TIdPeerThread *AThread)
{
BKUK_PACKET Pkt;
----------(Omission)---------------------------------------
//AThread->Connection->WriteBuffer(&Pkt,sizeof(BKUK_PACKET),1);
----------(Omission)---------------------------------------
}
在 Indy 10 中找不到名为 WriteBuffer() 的函数。是否有等效函数?
BKUK_PACKET是一个大约1200字节的结构。
typedef struct _BKUK_PACKET_
{
BYTE head[4];
WORD PayLoad;
WORD Length;
BYTE Data[1200];
WORD Ver;
BYTE tail[2];
}BKUK_PACKET;
我在查看 Indy 10 的说明手册时发现了 TIdIOHandler.Write(TIdBytes) 方法。
我参考了之前告诉你的代码:
Is there an equivalent of Indy 9's ReadBuffer() in Indy 10?
template<typename T>
void __fastcall PopulateWriteBuffer(T& obj,TIdIOHandler* ioh) {
System::Byte* p = (System::Byte*) &obj;
for(unsigned count=0; count<sizeof(T); ++count, ++p)
ioh->Write(*p);
----------(Omission)---------------------------------------
Populate02(&Pkt,AContext->Connection->IOHandler);
}
但是当我尝试像上面那样编程时,我得到一个错误:
[bcc32c 错误] Main.cpp(608): 没有匹配函数调用“Populate02”
Main.cpp(478):候选函数 [with T = _BKUK_PACKET_ *] 不可行:第一个参数没有从 '_PACKET *'(又名 '_BKUK_PACKET_ *')到 '_BKUK_PACKET_ *&' 的已知转换
请告诉我如何修复此代码。
【问题讨论】:
标签: c++ indy rad-studio