本文整理汇总了C++中TMemoryStream::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ TMemoryStream::Write方法的具体用法?C++ TMemoryStream::Write怎么用?C++ TMemoryStream::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMemoryStream
的用法示例。
在下文中一共展示了TMemoryStream::Write方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: keyStr
bool z3ResEx::z3Decrypt
(
TMemoryStream &src,
TMemoryStream &dst,
unsigned char *key,
unsigned int keylen
)
{
StringSource keyStr( key, keylen, true );
AutoSeededRandomPool rng;
ECIES<ECP>::Decryptor ellipticalEnc( keyStr );
unsigned char *tmpBuffer( new unsigned char[ src.Size() ] );
DecodingResult dr = ellipticalEnc.Decrypt( rng, src.Data(), src.Size(), tmpBuffer );
if( !( dr.isValidCoding ) || ( dr.messageLength == 0 ) )
{
delete tmpBuffer;
return false;
}
dst.Write( tmpBuffer, dr.messageLength );
delete tmpBuffer;
return true;
}
示例2: tmpOffset
bool z3ResEx::fsRle( TMemoryStream &src, TMemoryStream &dst, bool isMSF )
{
unsigned int msfSizeFlag;
unsigned int expectedSize, len;
unsigned char *pData( src.Data() ), *pDataEnd( pData + src.Size() );
if( isMSF )
{
// Read the expected size from data
msfSizeFlag = src.ReadUInt();
pData += 4;
}
if( !( z3Rle::decodeSize( pData, expectedSize, len ) ) )
{
dst.Close();
//printf("ERROR: Problems decoding RLE buffer size\n");
return false;
}
if( isMSF && !( msfSizeFlag == expectedSize ) )
{
dst.Close();
//printf("ERROR: Unexpected MSF buffer size\n");
return false;
}
// Skip the length of the expected size
pData += len;
unsigned char *tmpBuffer( new unsigned char[ expectedSize ] );
unsigned int tmpOffset( 0 );
while( tmpOffset < expectedSize )
{
if( !( z3Rle::decodeInstruction( pData, len, pDataEnd, tmpBuffer, tmpOffset ) ) )
{
delete tmpBuffer;
//printf("ERROR: Problems decoding RLE buffer\n");
return false;
}
pData += len;
}
dst.Write( tmpBuffer, expectedSize );
delete tmpBuffer;
return true;
}
示例3: SendButtonClick
//---------------------------------------------------------------------------
void __fastcall THttpTestForm::SendButtonClick(TObject *Sender)
{
TMemoryStream *DataIn;
TMemoryStream *DataOut;
AnsiString Buf;
BOOL bSuccess;
DisplayMemo->Clear();
DataIn = new TMemoryStream;
DataOut = new TMemoryStream;
bSuccess = TRUE;
try {
Buf = "ID=" + UserIDEdit->Text +
"&REMITE=" + EMailEdit->Text +
"&MENSAJE=" + Encode(MessageEdit->Text);
DataOut->Write(&Buf[1], Buf.Length());
DataOut->Seek(0, soFromBeginning);
HttpCli1->SendStream = DataOut;
HttpCli1->RcvdStream = DataIn;
HttpCli1->Proxy = ProxyEdit->Text;
HttpCli1->ProxyPort = "80";
HttpCli1->URL = "http://www.unired.net.pe/cgi-bin/a.out";
SendButton->Enabled = FALSE;
AbortButton->Enabled = TRUE;
try {
HttpCli1->Post();
}
__except (TRUE) {
bSuccess = FALSE;
}
if (bSuccess) {
DataIn->Seek(0, 0);
DisplayMemo->Lines->LoadFromStream(DataIn);
}
SendButton->Enabled = TRUE;
AbortButton->Enabled = FALSE;
}
__except (TRUE) {
bSuccess = FALSE;
}
if (!bSuccess)
DisplayMemo->Lines->Add("Failed : " + HttpCli1->ReasonPhrase);
delete DataOut;
delete DataIn;
}
示例4: PostButtonClick
//---------------------------------------------------------------------------
void __fastcall THttpTestForm::PostButtonClick(TObject *Sender)
{
TMemoryStream *DataOut;
TFileStream *DataIn;
AnsiString Buf;
int I;
DisplayMemo->Clear();
DocumentMemo->Clear();
SetButtonState(FALSE);
DataOut = new TMemoryStream;
Buf = DataEdit->Text;
DataOut->Write(&Buf[1], Buf.Length());
DataOut->Seek(0, soFromBeginning);
HttpCli1->SendStream = DataOut;
HttpCli1->Proxy = ProxyHostEdit->Text;
HttpCli1->ProxyPort = ProxyPortEdit->Text;
HttpCli1->RcvdStream = NULL;
HttpCli1->URL = URLEdit->Text;
try {
HttpCli1->Post();
} __except (TRUE) {
SetButtonState(TRUE);
delete DataOut;
DisplayMemo->Lines->Add("POST Failed !");
DisplayMemo->Lines->Add("StatusCode = " + IntToStr(HttpCli1->StatusCode));
DisplayMemo->Lines->Add("ReasonPhrase = " + HttpCli1->ReasonPhrase);
return;
}
delete DataOut;
DisplayMemo->Lines->Add("StatusCode = " + IntToStr(HttpCli1->StatusCode));
for (I = 0; I < HttpCli1->RcvdHeader->Count; I++)
DisplayMemo->Lines->Add("hdr>" + HttpCli1->RcvdHeader->Strings[I]);
DataIn = new TFileStream(HttpCli1->DocName, fmOpenRead);
DocumentMemo->Lines->LoadFromStream(DataIn);
delete DataIn;
SetButtonState(TRUE);
}
示例5: setGermanText
void __fastcall TAboutbox::setGermanText()
{
String t = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2055{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;} "
"{\\f1\\fswiss\\fcharset0 Arial;}} "
"\\viewkind4\\uc1\\pard\\b\\f0\\fs28 DB-BEAD\\b0\\f1\\fs20\\par "
"\\par "
"Dies ist DB-BEAD, ein Programm, das Ihnen beim Entwurf von geh\\'e4kelten "
"Perlenketten helfen soll. Die Erstellung solcher Ketten wird beispielsweise "
"im Buch 'Geh\\'e4kelte Glasperlenketten' von Lotti Gygax beschrieben. Die Arbeit ist aufw\\'e4ndig und "
"langwierig. Das Resultat entsch\\'e4digt aber f\\'fcr die erlittene M\\'fchsal.\\par "
"\\par "
"Mit DB-BEAD k\\'f6nnen Sie schon vor Beginn der Arbeit simulieren, wie Ihr "
"Entwurf als Kette dann aussehen wird. Direkt am Bildschirm k\\'f6nnen Sie "
"\\'c4nderungen vornehmen.\\par "
"\\par "
"Wenn Sie zufrieden mit dem Entwurf sind, k\\'f6nnen Sie alle notwendigen "
"Daten ausdrucken lassen, inklusive einer 'F\\'e4delliste', die hilfreich "
"f\\'fcr das Auff\\'e4deln der Perlen auf das H\\'e4kelgarn ist.\\par "
"\\par "
"DB-BEAD wurde von Damian Brunold geschrieben. Es steht unter der Lizenz "
"GPL v3, was bedeutet, dass Sie es kostenlos verwenden, kopieren und \\'e4ndern "
"d\\'fcrfen. Daf\\'fcr \\'fcbernimmt Damian Brunold absolut keine "
"Haftung f\\'fcr Fehler und Sch\\'e4den durch Benutzung des Programmes. "
"Sie m\\'fcssen selber entscheiden, ob das Programm f\\'fcr Sie n\\'fctzlich "
"ist oder nicht.\\par "
"\\par "
"Weitere Informationen erhalten Sie unter http://www.brunoldsoftware.ch "
"oder per E-Mail an [email protected] An diese Adresse k\\'f6nnen "
"Sie auch Fehler oder Verbesserungsvorschl\\'e4ge melden.\\par "
"\\par "
"Viel Spass mit dem Programm\\par "
"Damian Brunold\\par "
"}";
try {
TMemoryStream* ms = new TMemoryStream();
ms->Write (t.c_str(), t.Length());
ms->Position = 0;
text->Lines->LoadFromStream (ms);
delete ms;
} catch(...) {
}
}
示例6: setEnglishText
void __fastcall TAboutbox::setEnglishText()
{
String t = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2055{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;} "
"{\\f1\\fswiss\\fcharset0 Arial;}} "
"\\viewkind4\\uc1\\pard\\b\\f0\\fs28 DB-BEAD\\b0\\f1\\fs20\\par "
"\\par "
"This is DB-BEAD, a program designed to help you design crochet bead ropes. "
"The creation of such ropes is describes in e.g. the book "
"'Geh\\'e4kelte Glasperlenketten' written by Lotti Gygax. It is hard work to "
"create such a rope, but the result is very beautiful.\\par "
"\\par "
"With DB-BEAD you simulate before you start working how your design will "
"look like as a finished rope. You can make changes directly on the screen.\\par "
"\\par "
"After finishing the design, you can print out all relevant data "
"including a 'list of beads', which is very useful for correctly arranging "
"the beads onto the thread.\\par "
"\\par "
"DB-BEAD was written by Damian Brunold. It is freely available and licensed "
"under the GPL v3. This means, you can use and copy it freely and you can "
"create derivative works (if you are a programmer). Damian Brunold cannot "
"assume any liability for bugs and damage caused by using the program. "
"You have to decide for yourself whether the program is useful for you or not.\\par "
"\\par "
"More information is available at http://www.brunoldsoftware.ch or by sending "
"e-mail to [email protected] This also is the address to direct bug "
"reports or feature requests to.\\par "
"\\par "
"Have fun using DB-WEAVE\\par "
"Damian Brunold\\par "
"}";
try {
TMemoryStream* ms = new TMemoryStream();
ms->Write (t.c_str(), t.Length());
ms->Position = 0;
text->Lines->LoadFromStream (ms);
delete ms;
} catch(...) {
}
}
示例7: keyStr
bool z3ResEx::z3Decrypt
(
TMemoryStream &src,
TMemoryStream &dst,
unsigned char *key,
unsigned int keylen
)
{
StringSource keyStr( key, keylen, true );
AutoSeededRandomPool rng;
ECIES<ECP>::Decryptor ellipticalEnc( keyStr );
vector<unsigned char> tmpBuffer(src.Size());
DecodingResult dr = ellipticalEnc.Decrypt( rng, src.Data(), src.Size(), &tmpBuffer[0] );
if( dr.isValidCoding && dr.messageLength > 0 )
{
dst.Write(&tmpBuffer[0], dr.messageLength);
return true;
}
return false;
}
示例8: if
//.........这里部分代码省略.........
//'ファイルはver.1のアタッシェケースで暗号化されていません。';
MsgText = LoadResourceString(&Msgdecrypt::_MSG_ERROR_NOT_BLOWFISH_ENCRYPTION);
MsgType = mtError;
MsgButtons = TMsgDlgButtons() << mbOK;
MsgDefaultButton = mbOK;
Synchronize(&PostConfirmMessageForm);
goto LabelError;
}
//-----------------------------------
// 復号の準備
//-----------------------------------
bf = new CBlowFish;
bf->Initialize( KeyString.c_str(), KeyString.Length() ); //初期化
//-----------------------------------
// 暗号部ヘッダの復号(ECBモード)
//-----------------------------------
pms = new TMemoryStream;
len = 0;
while (len < EncryptHeaderSize) {
// 読み出しバッファ
for (c = 0; c < BUF_SIZE; c++) {
source_buffer[c] = 0;
}
// 暗号化されたデータブロックの読み出し
len += fsIn->Read(source_buffer, BUF_SIZE);
// 復号処理
bf->Decode( source_buffer, buffer, BUF_SIZE);
pms->Write(buffer, BUF_SIZE);
}
pms->Seek((__int64)0, TSeekOrigin::soBeginning); //ポインタを先頭へ戻す
DataList = new TStringList;
DataList->LoadFromStream(pms, TEncoding::GetEncoding(932)); // shift-jis
//-----------------------------------
// 復号正否(復号できたか)
//-----------------------------------
if (DataList->Count == 0 || DataList->Strings[0].Pos("AttacheCase") == 0) {
fPasswordOk = false;
}
else{
fPasswordOk = true; //パスワード合致
}
if ( fPasswordOk == false ) {
//'パスワードがちがいます。復号できません。'+#13+
//'場合によってはファイルが壊れている可能性もあります。';
MsgText = LoadResourceString(&Msgdecrypt::_MSG_ERROR_PASSWORD_WRONG);
MsgType = mtError;
MsgButtons = TMsgDlgButtons() << mbOK;
MsgDefaultButton = mbOK;
Synchronize(&PostConfirmMessageForm);
delete DataList;
goto LabelTypeMiss;
}
//-----------------------------------
// 復号時のエンコーディング判定
//-----------------------------------
示例9: Request
//---------------------------------------------------------------------------
int __fastcall TTrdCot_Rm::Request(TRequest Request,TAnswer **Answer,int &AnsCount)
{
TAnswer answer;
int retVal = 0;
Request.Head.Version = 2010;
try
{
TMemoryStream* dest = new TMemoryStream();
int orgsize = sizeof(Request) ;
dest->Write(&orgsize,sizeof(int));
TCompressionStream * cs = new TCompressionStream(Zlib::clDefault,dest);
TMemoryStream *source = new TMemoryStream();
TDecompressionStream *ds = new TDecompressionStream(source);
FCS->Enter();
try
{
memset(&answer,0,sizeof(TAnswer));
if( Request.Head.FuncType == ftInit)
{
this->Connect();
if( FTcpClt->Connected() == false )
return ERR_TRDSVR_SEND_FAILED;
FTcpClt->Socket->UseNagle = false;
}
cs->Write(&Request,sizeof(Request));
delete cs;
cs = NULL;
if( FTcpClt == NULL ) return -1000;
// 发送请求
try
{
FTcpClt->IOHandler->LargeStream = false;
FTcpClt->IOHandler->Write(dest,0x000000000,true);
}
catch(...)
{
retVal = ERR_TRDSVR_SEND_FAILED;
FTcpClt->Disconnect();
return retVal;
}
delete dest;
dest = NULL;
// 接收响应
try
{
int size = FTcpClt->IOHandler->ReadInteger(false);
if( size >0 )
{
orgsize = FTcpClt->IOHandler->ReadInteger(false);
FTcpClt->IOHandler->ReadStream(source,size-sizeof(int),false);
if( sizeof(TAnswer) != ds->Read(&answer,sizeof(TAnswer)) )
{
throw "";
}
}
else
{
throw "";
}
}
catch(...)
{
retVal = ERR_TRDSVR_RECV_FAILED;
FTcpClt->Disconnect();
return retVal;
}
retVal = answer.Head.RetVal;
if(retVal==0)
{
AnsCount = answer.Head.AnsCount;
if(AnsCount>0)
{
*Answer = new TAnswer[AnsCount];
try
{
memcpy(&(*Answer)[0],&answer,sizeof(TAnswer));
int len = sizeof(TAnswer)*(AnsCount-1);
if( len!= ds->Read(&(*Answer)[1],len))
{
throw "";
}
}
catch(...)
{
delete [] (*Answer);
retVal= ERR_TRDSVR_RECV_FAILED;
FTcpClt->Disconnect();
return retVal;
}
}
//.........这里部分代码省略.........
示例10: if
//.........这里部分代码省略.........
// 暗号部ヘッダの復号
//-----------------------------------
pms = new TMemoryStream;
// IVの読み込み
fsIn->Read(chain_buffer, BUF_SIZE);
len = 0;
while (len < EncryptHeaderSize) {
// 読み出しバッファ
for (c = 0; c < BUF_SIZE; c++) {
source_buffer[c] = 0;
}
// 暗号化されたデータブロックの読み出し
len += fsIn->Read(source_buffer, BUF_SIZE);
for (c = 0; c < BUF_SIZE; c++) {
// あとのxorのためによけておく
temp_buffer[c] = source_buffer[c];
}
// 復号処理
rijndael_decrypt(source_buffer);
// xor
for (c = 0; c < BUF_SIZE; c++) {
source_buffer[c] ^= chain_buffer[c];
chain_buffer[c] = temp_buffer[c]; // CBC
}
pms->Write(source_buffer, BUF_SIZE);
}
pms->Seek((__int64)0, TSeekOrigin::soBeginning); //ポインタを先頭へ戻す
DataList = new TStringList;
DataList->LoadFromStream(pms, TEncoding::GetEncoding(932)); // shift-jis
//-----------------------------------
// 復号正否(復号できたか)
//-----------------------------------
//MsgText = DataList->Strings[0];
//MsgType = mtError;
//MsgButtons = TMsgDlgButtons() << mbOK;
//MsgDefaultButton = mbOK;
//Synchronize(&PostConfirmMessageForm);
if (DataList->Count == 0 || DataList->Strings[0].Pos("AttacheCase") == 0) {
fPasswordOk = false;
}
else{
fPasswordOk = true; //パスワード合致
}
if ( fPasswordOk == false ) {
//'パスワードがちがいます。復号できません。'+#13+
//'場合によってはファイルが壊れている可能性もあります。';
MsgText = LoadResourceString(&Msgdecrypt::_MSG_ERROR_PASSWORD_WRONG);
if ( fCompare == true ) {
//メッセージに'コンペアに失敗しました。'を追加
MsgText += "\n" + LoadResourceString(&Msgdecrypt::_MSG_ERROR_COMPARE_FILE);
}
示例11: if
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
TMemoryStream *d = new TMemoryStream();
FormelIntr *fi = new FormelIntr();
long double res;
long double max = 0;
#define VARCOUNT 3
FormIntrVar vars[VARCOUNT] = {
{ "rand" , 0 } ,
{ "t" , 0 } ,
{ "pi" , 3.141592654 }
};
FormIntrError error;
int SampRate = StrToInt ( ComboBox1->Text.SubString ( 1, 5 ) );
randomize();
for ( long double i = 0;
i < CSpinEdit1->Value * SampRate; i++ ) {
vars[0].Val =
(long double)(rand()*rand()) / ((long double)rand()+1);
vars[1].Val = (long double)i / (long double)SampRate;
fi->Calc ( res, Edit1->Text.c_str(), VARCOUNT, vars, error );
if ( error.ErrNum != 0 ) res = 0.0;
d->Write ( &res, sizeof ( res ) );
if ( res > max ) max = res;
else if ( res < (-max) ) max = -res;
}
if ( max == 0 ) {
delete d;
delete fi;
OUTPUT ( "Error" );
return;
}
long double scal = (long double)30000 / max;
delete SoundBuffer;
SoundBuffer = new TMemoryStream();
Chart1->Series[0]->Clear();
Chart2->Series[0]->Clear();
WaveHeader ( SoundBuffer, SampRate, d->Size / sizeof(res) );
d->Position = 0;
short signed end = -1;
short unsigned x1, x2;
x2 = CSpinEdit2->Value;
x1 = 0;
while ( d->Read ( &res, sizeof(res) ) == sizeof( res ) ) {
end = ( res * scal );
SoundBuffer->Write ( &end, 2 );
if ( x1 <= 0 ) {
Chart1->Series[0]->AddY ( end, "", clTeeColor );
Chart2->Series[0]->AddY ( end, "", clTeeColor );
x1 = x2;
}
x1--;
}
delete d;
delete fi;
OUTPUT ( "Created" );
}
示例12: AcceptClient
void TClientSockThread::AcceptClient()
{
int iResult;
int iSendResult;
char recvbuf[DEFAULT_BUFLEN];
char sandbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
bool IsData;
int CommandID, CurCommandID;
int DataType, CurDataType;
TMemoryStream *ms = new TMemoryStream;
if (Authentication(ClientSocket, ms)) {
CurCommandID = -1;
// Receive until the peer shuts down the connection
do {
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if (iResult > 0) {
Form1->m->Lines->Append("Bytes received: " + IntToStr(iResult));
CommandID = GetCommand(recvbuf, iResult);
if (CommandID == CM_EXEC) {
RunCommand( ClientSocket, CurCommandID, ms);
StrCopy(sandbuf, "ok\0");
iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
}
else if (CommandID) {
CurCommandID = CommandID;
ms->Clear();
StrCopy(sandbuf, "ok\0");
iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
}
else {
ms->Write(recvbuf, iResult);
StrCopy(sandbuf, "ok\0");
iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
}
//
// Echo the buffer back to the sender
// iSendResult = send( ClientSocket, recvbuf, iResult, 0 );
// if (iSendResult == SOCKET_ERROR) {
// Form1->m->Lines->Append("send failed with error: " + IntToStr(WSAGetLastError()));
// closesocket(ClientSocket);
// WSACleanup();
// return;
// }
// Form1->m->Lines->Append("Bytes sent: " + IntToStr(iSendResult));
}
else if (iResult == 0)
Form1->m->Lines->Append("Connection closing...\n");
else {
Form1->m->Lines->Append("recv failed with error: " + IntToStr(WSAGetLastError()));
closesocket(ClientSocket);
WSACleanup();
delete ms;
return;
}
} while (iResult > 0);
}
// shutdown the connection since we're done
iResult = shutdown(ClientSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
Form1->m->Lines->Append("shutdown failed with error: " + IntToStr(WSAGetLastError()));
closesocket(ClientSocket);
WSACleanup();
delete ms;
return;
}
// cleanup
closesocket(ClientSocket);
delete ms;
}
示例13: SendToRecvBuf
//添加数据到接收缓冲
void TFComm::SendToRecvBuf(UINT8 *pstream, UINT32 szLen)
{
TMemoryStream *pms = new TMemoryStream();
pms->Write(pstream, szLen);
m_Recv->Push(pms);
}