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

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

  2. <tfoot id='LI5Kp'></tfoot>

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

      如何在 VC++ 静态库中加载自定义二进制资源作为 dll 的一部分?

      How to load a custom binary resource in a VC++ static library as part of a dll?(如何在 VC++ 静态库中加载自定义二进制资源作为 dll 的一部分?)

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

          <tbody id='XGdj9'></tbody>
        <tfoot id='XGdj9'></tfoot>

              • <bdo id='XGdj9'></bdo><ul id='XGdj9'></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 的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)
                <i id='UaiOy'><tr id='UaiOy'><dt id='UaiOy'><q id='UaiOy'><span id='UaiOy'><b id='UaiOy'><form id='UaiOy'><ins id='UaiOy'></ins><ul id='UaiOy'></ul><sub id='UaiOy'></sub></form><legend id='UaiOy'></legend><bdo id='UaiOy'><pre id='UaiOy'><center id='UaiOy'></center></pre></bdo></b><th id='UaiOy'></th></span></q></dt></tr></i><div id='UaiOy'><tfoot id='UaiOy'></tfoot><dl id='UaiOy'><fieldset id='UaiOy'></fieldset></dl></div>
                • <bdo id='UaiOy'></bdo><ul id='UaiOy'></ul>
                  <legend id='UaiOy'><style id='UaiOy'><dir id='UaiOy'><q id='UaiOy'></q></dir></style></legend>
                  <tfoot id='UaiOy'></tfoot>
                    <tbody id='UaiOy'></tbody>

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