<legend id='poLdd'><style id='poLdd'><dir id='poLdd'><q id='poLdd'></q></dir></style></legend>
      <bdo id='poLdd'></bdo><ul id='poLdd'></ul>
  • <small id='poLdd'></small><noframes id='poLdd'>

    1. <i id='poLdd'><tr id='poLdd'><dt id='poLdd'><q id='poLdd'><span id='poLdd'><b id='poLdd'><form id='poLdd'><ins id='poLdd'></ins><ul id='poLdd'></ul><sub id='poLdd'></sub></form><legend id='poLdd'></legend><bdo id='poLdd'><pre id='poLdd'><center id='poLdd'></center></pre></bdo></b><th id='poLdd'></th></span></q></dt></tr></i><div id='poLdd'><tfoot id='poLdd'></tfoot><dl id='poLdd'><fieldset id='poLdd'></fieldset></dl></div>

      1. <tfoot id='poLdd'></tfoot>

        在 C++ 中以编程方式将资源加载为字节数组

        时间:2023-05-23
              <tbody id='XnZVj'></tbody>

            <tfoot id='XnZVj'></tfoot>
            <i id='XnZVj'><tr id='XnZVj'><dt id='XnZVj'><q id='XnZVj'><span id='XnZVj'><b id='XnZVj'><form id='XnZVj'><ins id='XnZVj'></ins><ul id='XnZVj'></ul><sub id='XnZVj'></sub></form><legend id='XnZVj'></legend><bdo id='XnZVj'><pre id='XnZVj'><center id='XnZVj'></center></pre></bdo></b><th id='XnZVj'></th></span></q></dt></tr></i><div id='XnZVj'><tfoot id='XnZVj'></tfoot><dl id='XnZVj'><fieldset id='XnZVj'></fieldset></dl></div>

            1. <small id='XnZVj'></small><noframes id='XnZVj'>

              • <legend id='XnZVj'><style id='XnZVj'><dir id='XnZVj'><q id='XnZVj'></q></dir></style></legend>
                  <bdo id='XnZVj'></bdo><ul id='XnZVj'></ul>

                  本文介绍了在 C++ 中以编程方式将资源加载为字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这里是 C# 的相同问题:以字节数组编程方式加载资源

                  Here the same question for C#: load resource as byte array programmaticaly

                  所以我有一个资源(只是二进制文件 - 用户数据,并不重要).我需要获取一个指向表示此资源的字节数组的指针,如何执行此操作?资源位于 vs2010(win32 控制台项目)的 Resource Files 中.我想我需要使用winapi的FindResourceLoadResourceLockResource函数.

                  So I've got a resource (just binary file - user data, dosen't really matter). I need to get a pointer to byte array representing this resource, how to do this ? Resource located in Resource Files of vs2010 (win32 console project). I think i need to use FindResource, LoadResource and LockResource function of winapi.

                  推荐答案

                  要获取资源的字节信息,第一步是使用FindResource 或 FindResourceEx.然后,使用加载资源LoadResource.最后,使用 LockResource 获取数据地址并访问 SizeofResource 字节.以下示例说明了该过程:

                  To obtain the byte information of the resource, the first step is to obtain a handle to the resource using FindResource or FindResourceEx. Then, load the resource using LoadResource. Finally, use LockResource to get the address of the data and access SizeofResource bytes from that point. The following example illustrates the process:

                  HMODULE hModule = GetModuleHandle(NULL); // get the handle to the current module (the executable file)
                  HRSRC hResource = FindResource(hModule, MAKEINTRESOURCE(RESOURCE_ID), RESOURCE_TYPE); // substitute RESOURCE_ID and RESOURCE_TYPE.
                  HGLOBAL hMemory = LoadResource(hModule, hResource);
                  DWORD dwSize = SizeofResource(hModule, hResource);
                  LPVOID lpAddress = LockResource(hMemory);
                  
                  char *bytes = new char[dwSize];
                  memcpy(bytes, lpAddress, dwSize);
                  

                  为简洁起见,当然省略了错误处理,您应该检查每个调用的返回值.

                  Error handling is of course omitted for brevity, you should check the return value of each call.

                  这篇关于在 C++ 中以编程方式将资源加载为字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么函数不能在 Main 之后 下一篇:`struct X typedef` 与 `typedef struct X` 的含义是什么?

                  相关文章

                  最新文章

                    <small id='y2Z2C'></small><noframes id='y2Z2C'>

                    <i id='y2Z2C'><tr id='y2Z2C'><dt id='y2Z2C'><q id='y2Z2C'><span id='y2Z2C'><b id='y2Z2C'><form id='y2Z2C'><ins id='y2Z2C'></ins><ul id='y2Z2C'></ul><sub id='y2Z2C'></sub></form><legend id='y2Z2C'></legend><bdo id='y2Z2C'><pre id='y2Z2C'><center id='y2Z2C'></center></pre></bdo></b><th id='y2Z2C'></th></span></q></dt></tr></i><div id='y2Z2C'><tfoot id='y2Z2C'></tfoot><dl id='y2Z2C'><fieldset id='y2Z2C'></fieldset></dl></div>
                      <bdo id='y2Z2C'></bdo><ul id='y2Z2C'></ul>
                  1. <tfoot id='y2Z2C'></tfoot>

                    1. <legend id='y2Z2C'><style id='y2Z2C'><dir id='y2Z2C'><q id='y2Z2C'></q></dir></style></legend>