久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='M5QMs'><style id='M5QMs'><dir id='M5QMs'><q id='M5QMs'></q></dir></style></legend>
    <tfoot id='M5QMs'></tfoot>

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

      • <bdo id='M5QMs'></bdo><ul id='M5QMs'></ul>

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

      在本機(jī) Windows 應(yīng)用程序的資源中嵌入文本文件

      Embed Text File in a Resource in a native Windows Application(在本機(jī) Windows 應(yīng)用程序的資源中嵌入文本文件)

        <bdo id='ccilI'></bdo><ul id='ccilI'></ul>
        <tfoot id='ccilI'></tfoot>
        <i id='ccilI'><tr id='ccilI'><dt id='ccilI'><q id='ccilI'><span id='ccilI'><b id='ccilI'><form id='ccilI'><ins id='ccilI'></ins><ul id='ccilI'></ul><sub id='ccilI'></sub></form><legend id='ccilI'></legend><bdo id='ccilI'><pre id='ccilI'><center id='ccilI'></center></pre></bdo></b><th id='ccilI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ccilI'><tfoot id='ccilI'></tfoot><dl id='ccilI'><fieldset id='ccilI'></fieldset></dl></div>
            <tbody id='ccilI'></tbody>
        • <legend id='ccilI'><style id='ccilI'><dir id='ccilI'><q id='ccilI'></q></dir></style></legend>

            • <small id='ccilI'></small><noframes id='ccilI'>

                本文介紹了在本機(jī) Windows 應(yīng)用程序的資源中嵌入文本文件的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我有一個(gè) C++ Windows 程序.我有一個(gè)包含一些數(shù)據(jù)的文本文件.目前,文本文件是一個(gè)單獨(dú)的文件,它在運(yùn)行時(shí)加載并解析.如何將其作為資源嵌入到二進(jìn)制文件中?

                I have a C++ Windows program. I have a text file that has some data. Currently, the text file is a separate file, and it is loaded at runtime and parsed. How is it possible to embed this into the binary as a resource?

                推薦答案

                由于您正在開(kāi)發(fā)本機(jī) Windows 應(yīng)用程序,因此您想要做的是創(chuàng)建一個(gè)用戶(hù)定義的資源,將文本文件的內(nèi)容嵌入到編譯后的資源.

                Since you're working on a native Windows application, what you want to do is to create a user-defined resource to embed the contents of the text file into the compiled resource.

                用戶(hù)定義資源的格式是記錄在MSDN,加載它的函數(shù).

                The format of a user-defined resource is documented on MSDN, as are the functions for loading it.

                您將文本文件嵌入到資源文件中,如下所示:

                You embed your text file in a resource file like this:

                nameID typeID filename
                

                其中 nameID 是標(biāo)識(shí)資源的唯一 16 位無(wú)符號(hào)整數(shù),typeID 是標(biāo)識(shí)資源類(lèi)型的某個(gè)大于 255 的唯一 16 位無(wú)符號(hào)整數(shù)(您可以在 resource.h 文件中定義這些整數(shù)).filename 是您要將其二進(jìn)制內(nèi)容嵌入到已編譯資源中的文件的路徑.

                where nameID is some unique 16-bit unsigned integer that identifies the resource and typeID is some unique 16-bit unsigned integer greater than 255 that identifies the resource type (you may define those integers in the resource.h file). filename is the path to the file that you want to embed its binary contents into the compiled resource.

                所以你可能是這樣的:

                resource.h中:

                // Other defines...
                
                #define TEXTFILE        256
                #define IDR_MYTEXTFILE  101
                

                在您的資源文件中:

                #include "resource.h"
                
                // Other resource statements...
                
                IDR_MYTEXTFILE TEXTFILE "mytextfile.txt"
                

                然后你像這樣加載它(為了清楚起見(jiàn)省略了錯(cuò)誤檢查代碼):

                Then you load it like this (error-checking code omitted for clarity):

                #include <windows.h>
                #include <cstdio>
                #include "resource.h"
                
                void LoadFileInResource(int name, int type, DWORD& size, const char*& data)
                {
                    HMODULE handle = ::GetModuleHandle(NULL);
                    HRSRC rc = ::FindResource(handle, MAKEINTRESOURCE(name),
                        MAKEINTRESOURCE(type));
                    HGLOBAL rcData = ::LoadResource(handle, rc);
                    size = ::SizeofResource(handle, rc);
                    data = static_cast<const char*>(::LockResource(rcData));
                }
                
                // Usage example
                int main()
                {
                    DWORD size = 0;
                    const char* data = NULL;
                    LoadFileInResource(IDR_MYTEXTFILE, TEXTFILE, size, data);
                    /* Access bytes in data - here's a simple example involving text output*/
                    // The text stored in the resource might not be NULL terminated.
                    char* buffer = new char[size+1];
                    ::memcpy(buffer, data, size);
                    buffer[size] = 0; // NULL terminator
                    ::printf("Contents of text file: %s
                ", buffer); // Print as ASCII text
                    delete[] buffer;
                    return 0;
                }
                

                請(qǐng)注意,您實(shí)際上不必釋放資源,因?yàn)橘Y源駐留在可執(zhí)行文件的二進(jìn)制文件中,系統(tǒng)會(huì)在程序退出時(shí)自動(dòng)刪除它們(函數(shù) FreeResource()在 32 位和 64 位 Windows 系統(tǒng)上沒(méi)有任何內(nèi)容).

                Note that you don't actually have to free the resource since the resource resides in the binary of the executable and the system will delete them automatically when the program exits (the function FreeResource() does nothing on 32-bit and 64-bit Windows systems).

                因?yàn)閿?shù)據(jù)駐留在可執(zhí)行二進(jìn)制文件中,您不能直接通過(guò)檢索到的指針修改它(這就是為什么 LoadFileInResource() 函數(shù)實(shí)現(xiàn)將指針存儲(chǔ)在 const char* 中的原因)).您需要使用 BeginUpdateResource()、UpdateResource()EndUpdateResource() 函數(shù)來(lái)做到這一點(diǎn).

                Because the data resides in the executable binary, you can't modify it via the retrieved pointer directly (that's why the LoadFileInResource() function implementation stores the pointer in a const char*). You need to use the BeginUpdateResource(), UpdateResource(), and EndUpdateResource() functions to do that.

                這篇關(guān)于在本機(jī) Windows 應(yīng)用程序的資源中嵌入文本文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒(méi)有異常時(shí),C++ 異常會(huì)以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對(duì) const 的引用?)
                When and how should I use exception handling?(我應(yīng)該何時(shí)以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對(duì)象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說(shuō)明符 C++11 noexcept 之間的區(qū)別)
                <legend id='5lRlV'><style id='5lRlV'><dir id='5lRlV'><q id='5lRlV'></q></dir></style></legend>
                • <bdo id='5lRlV'></bdo><ul id='5lRlV'></ul>

                  <i id='5lRlV'><tr id='5lRlV'><dt id='5lRlV'><q id='5lRlV'><span id='5lRlV'><b id='5lRlV'><form id='5lRlV'><ins id='5lRlV'></ins><ul id='5lRlV'></ul><sub id='5lRlV'></sub></form><legend id='5lRlV'></legend><bdo id='5lRlV'><pre id='5lRlV'><center id='5lRlV'></center></pre></bdo></b><th id='5lRlV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5lRlV'><tfoot id='5lRlV'></tfoot><dl id='5lRlV'><fieldset id='5lRlV'></fieldset></dl></div>
                    1. <tfoot id='5lRlV'></tfoot>
                    2. <small id='5lRlV'></small><noframes id='5lRlV'>

                        <tbody id='5lRlV'></tbody>

                          主站蜘蛛池模板: 亚洲最大av网站 | 日韩欧美视频 | 日韩中文字幕精品 | 五月色综合 | 欧美成人精品欧美一级乱黄 | av天天操| 精品伊人久久 | 色婷婷av一区二区三区之e本道 | 亚洲国产精品久久久 | 日韩精品视频一区二区三区 | 蜜臀av性久久久久av蜜臀妖精 | 成人在线国产 | 亚洲精品成人 | 538在线 | 国产成人+综合亚洲+天堂 | 4hu在线 | 成人小视频在线观看 | 在线性视频 | 日韩免费看片 | 欧美高清视频在线观看mv | 欧美一区二区三区四区五区 | 日韩久久久久久久 | 天堂av在线资源 | 99久久精品一区二区成人 | 日韩精品久久久久久免费 | 亚洲 欧美 另类 综合 偷拍 | 久久久久久久久久一区二区三区 | 四虎永久在线 | 国产高清一区 | 欧美激情免费 | 日本成人一区二区三区 | 亚洲精品a | 中文字幕综合网 | 69成人网| 91精品国产综合久久久蜜臀九色 | 中文字幕黄色片 | 欧美成人一级 | 免费视频一区二区 | 国产日产精品一区二区三区的介绍 | 亚洲欧美中文字幕 | 午夜三级|