CStream

freevelog·2024년 1월 20일
0

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) {}

변수 선언
일반 변수

CStream 클래스

CStream 클래스변수 메모리지정

Stream.WriteInt32(Data1) 진행

Stream.WriteBytes(Data4, 32) 진행

[아래는 다시 디버깅한 상태라 주소값다름]

0개의 댓글