[英]Array<byte>^ in Win32
我有一个为Metro风格编写的DirectX 11.1程序,我想将其转换为Win32应用程序。 我使用了很多WinRT库,其中大多数是为HWND创建的。 但我仍然有一个问题:
在Metro Style应用程序上,为了使用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 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.