mercredi 16 décembre 2020

C++ Copy Raw std::bytes to std::vector

I have an FILE_NOTIFY_INFORMATION struct which i have filled like this:

FILE_NOTIFY_INFORMATION* fni = new FILE_NOTIFY_INFORMATION;
fni->Action = 1;
wcscpy_s(fni->FileName,12, L"example.txt");
fni->FileNameLength = 12;
fni->NextEntryOffset = 0;

I have then castet this Struct to an std::byte*.

auto fni_as_byte = reinterpret_cast<std::byte*>(fni);

Now i want to put this fni_as_byte into an vector of std::vector<std::byte>. Because i need this for testing purpose.

Normally you receive the FILE_NOTIFY_INFORMATION for example from the ReadDirectoryChangesW function. And it's called like this:

std::vector<std::byte> notifyBuffer{1024};
res = ReadDirectoryChangesW(handle, notifyBuffer.data(), static_cast<DWORD>(notifyBuffer.size()), false, FILE_NOTIFY_CHANGE_FILE_NAME, nullptr, &overlapped, nullptr);

So how can i manually copy the castet FILE_NOTIFY_INFORMATION into the std::vector<std::byte>?

Aucun commentaire:

Enregistrer un commentaire