main.cpp
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include "Stream.h"
void main()
{
BYTE Buffer[12] = { 1,2,3 };
INT Data1 = 4;
INT Data2 = 5;
INT Data3 = 6;
BYTE Data4[] = { 7 };
CStream Stream;
Stream.SetBuffer(Buffer);
Stream.WriteInt32(Data1);
Stream.WriteBytes(Data4, 32);
Stream.WriteInt32(Data2);
Stream.WriteInt32(Data3);
}
Stream.h
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
class CStream
{
private:
BYTE *mBufferpointer;
DWORD mLength;
public:
BOOL SetBuffer(BYTE *buffer);
BOOL WriteInt32(INT data);
BOOL WriteBytes(BYTE *data, DWORD length);
public:
CStream(VOID);
~CStream(VOID);
};
Stream.cpp
#include "Stream.h"
BOOL CStream::SetBuffer(BYTE *buffer)
{
if (!buffer) return FALSE;
mBufferpointer = buffer;
mLength = 0;
return TRUE;
}
BOOL CStream::WriteInt32(INT data)
{
CopyMemory(mBufferpointer + mLength, &data, sizeof(INT));
mLength += sizeof(INT);
return TRUE;
}
BOOL CStream::WriteBytes(BYTE *data, DWORD length)
{
CopyMemory(mBufferpointer + mLength, data, length);
mLength += length;
return TRUE;
}
CStream::CStream(VOID)
{
mBufferpointer = NULL;
mLength = 0;
}
CStream::~CStream(VOID) {}
변수 선언
Stream.WriteInt32(Data1) 진행
Stream.WriteBytes(Data4, 32) 진행
[아래는 다시 디버깅한 상태라 주소값다름]