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>?
std::vector<std::byte> notifyBuffer{1024};-- This creates a vector of one element, with that value being 1024. Is this what you want?notifyBuffer(1024)ornotifyBuffer({1024})are so much more obvious...std::vectoralso has a constructor that takes astd::initializer_list. That is the constructor thatnotifyBuffer{1024}will call, not the size constructor you are thinking of. If thatinitializer_listconstructor didn’t exist, then yes, the size constructor would be called instead.