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

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

    2. 如何在 VC++ 静态库中加载自定义二进制资源作为

      时间:2023-10-06

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

          <i id='a1DDP'><tr id='a1DDP'><dt id='a1DDP'><q id='a1DDP'><span id='a1DDP'><b id='a1DDP'><form id='a1DDP'><ins id='a1DDP'></ins><ul id='a1DDP'></ul><sub id='a1DDP'></sub></form><legend id='a1DDP'></legend><bdo id='a1DDP'><pre id='a1DDP'><center id='a1DDP'></center></pre></bdo></b><th id='a1DDP'></th></span></q></dt></tr></i><div id='a1DDP'><tfoot id='a1DDP'></tfoot><dl id='a1DDP'><fieldset id='a1DDP'></fieldset></dl></div>
        1. <tfoot id='a1DDP'></tfoot>
            <legend id='a1DDP'><style id='a1DDP'><dir id='a1DDP'><q id='a1DDP'></q></dir></style></legend>
                <tbody id='a1DDP'></tbody>
              • <bdo id='a1DDP'></bdo><ul id='a1DDP'></ul>
                本文介绍了如何在 VC++ 静态库中加载自定义二进制资源作为 dll 的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有自定义二进制资源(动画游标),希望将其作为资源存储在 Visual Studio C++ 的静态库中.事实证明,如果自定义二进制资源是自定义资源且位于静态库中,则 ::LoadCursor() 将不会加载或由 ::FindResource() 找到自定义二进制资源.

                I have custom binary resources (animated cursors) that would like to store as resources in a static lib in Visual Studio C++. It turns out that custom binary resources will not get loaded by ::LoadCursor() or found by ::FindResource() if it is a custom resource and in a static library.

                这个问题提供了一些解决方法.

                按照它的建议,如果我将 *.res 文件作为配置属性->链接器->附加依赖项"添加到 exe 中,那么静态库将能够找到该资源.

                Following its advice, if I add the *.res file to an exe as a "Configuration Property->Linker->Additional Dependency" then the static library will be able to find the resource.

                但是,如果静态库是 dll 的一部分,并且我将其作为附加依赖项链接,则不会再次找到它!

                BUT if the static library is part of a dll and I link it in as an Additional Dependency it is not found again!

                如何链接 dll 中的资源?

                How can I link the resources in a dll?

                或者只是在静态库中找到二进制文件?问题中的方法相当繁琐.

                Or just make the binary be found in the static lib? The methods in the question are pretty cumbersome.

                推荐答案

                在添加资源"对话框中单击导入",选择所有文件 (.)",以便它允许您导入任何类型的文件,然后只需选择您想要的文件.当自定义资源类型对话框弹出时,在资源类型"字段中输入 RCDATA.

                In Add Resource dialog click Import, select "All Files (.)" so that it allows you to import file of any type, and then just select the file you want there. When Custom Resource Type dialog pops up, type RCDATA into "Resource type" field.

                如果你打开 .rc 文件,你会看到如下内容:

                If you open .rc file, you will see something like this:

                /////////////////////////////////////////////////////////////////////////////
                //
                // RCDATA
                //
                
                IDR_RCDATA1          RCDATA               "myfile.whatever"
                

                它将生成带有以下行的 resource.h:

                and it will generate resource.h with following line:

                #define IDR_RCDATA1                  101
                

                在代码中,您可以像这样访问它:

                In code you access it like this:

                #include "resource.h"
                #include <windows.h>
                
                int main(int argc, char* argv[])
                {
                    HRSRC myResource = ::FindResource(NULL, MAKEINTRESOURCE(IDR_RCDATA1), RT_RCDATA);
                    HGLOBAL myResourceData = ::LoadResource(NULL, myResource);
                    void* pMyBinaryData = ::LockResource(myResourceData);
                    return 0;
                }
                

                其中 pMyBinaryData 是指向此可执行文件的第一个字节的指针.欲了解更多信息,请访问资源函数

                where pMyBinaryData is pointer to first byte of this executable. For more information visit Resource Functions

                以下是如何在磁盘上保存这样的二进制资源的示例:

                Here's an example how you would save binary resource like this on disk:

                #include "resource.h"
                #include <windows.h>
                #include <fstream>
                
                int main(int argc, char* argv[])
                {
                    HRSRC myResource = ::FindResource(NULL, MAKEINTRESOURCE(IDR_RCDATA1), RT_RCDATA);
                    unsigned int myResourceSize = ::SizeofResource(NULL, myResource);
                    HGLOBAL myResourceData = ::LoadResource(NULL, myResource);
                    void* pMyBinaryData = ::LockResource(myResourceData);
                
                    std::ofstream f("C:\x.bin", std::ios::out | std::ios::binary);
                    f.write((char*)pMyBinaryData, myResourceSize);
                    f.close();
                
                    return 0;
                }
                

                当您使用这样的资源构建项目时,该资源将成为您的程序 (dll) 的一部分.

                When you build project with resource like that, this resource will become part of your program (dll).

                这篇关于如何在 VC++ 静态库中加载自定义二进制资源作为 dll 的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:VC++ 致命错误 LNK1168:无法打开 filename.exe 进行写入 下一篇:原子的 C++ 内存屏障

                相关文章

                最新文章

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

                  <legend id='ocSpJ'><style id='ocSpJ'><dir id='ocSpJ'><q id='ocSpJ'></q></dir></style></legend>

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