<byte>Array^ in Win32

Array<byte>^ in Win32

本文关键字:Win32 in gt lt byte Array      更新时间:2023-10-16

我有一个为Metro风格编写的DirectX 11.1程序,我想将其转换为Win32应用程序。我使用过很多 WinRT 库,其中大多数都是为 HWND 建立的。但我仍然有一个问题:

在地铁风格应用程序上,为了使用 HLSL 文件,这就是我使用的:

inline Platform::Array<byte>^ ReadFile(Platform::String^ path)
{
    using namespace Platform;
Array<byte>^ bytes = nullptr;
FILE* f = nullptr;
_wfopen_s(&f, path->Data(), L"rb");
if (f == nullptr)
{
    throw ref new Exception(0, "Could not open file on following path : " + path);
}
else
{
    fseek(f, 0, SEEK_END);
    auto pos = ftell(f);
    bytes = ref new Array<byte>(pos);
    fseek(f, 0, SEEK_SET);
    // read data into the prepared buffer
    if (pos > 0)
    {
        fread(&bytes[0], 1, pos, f);
    }
    // close the file
    fclose(f);
}
return bytes;
}

但我不知道 Win32 (hwnd) 风格应用程序的数组Array<byte>^的等效项。高度赞赏任何指南

我们可以用std::vector<unsigned char>代替:

std::vector<unsigned char> ReadFile(std::wstring path)
{
    std::vector<unsigned char> bytes;
    ...
    _wfopen_s(&f, path.c_str(), L"rb");
    ...
    bytes.resize(pos);
    ...
    fread(bytes.data(), 1, pos, f);
    ...
    return bytes;
}