VC production pure resource DLL

xiaoxiao2021-03-06  23

Back up your procedure first before doing it! ! !

Sometimes the program requires a lot of BMP or other resources, so after adding the resource to the program, the exe file will be large. At this time we can pack resources in the program into a pure resource DLL. (The original program XXAPP, pure resource program XXDLL)

The pure resource DLL file implementation steps are as follows:

(1) New establishment of XXDLL. Use Projects Win32 Dynamic-Link Library to create a pure resource DLL project (that is, empty project), add .rc, .rc2, .ico, .bmp et al (other resource) files created by your program to the project. Document;

You should first find the resource.h, xxapp.rc files in the XXAPP program, and the folder you store resources (I usually put the program used in the RES folder under the VC program folder, so I will The RES folder can be added to the XXDLL program :)! ), Join these to the XXDLL program.

(2) XXAPP program (at this time, there is resources), automatically created .rc, .rc2, .ico, .bmp such as VC framework (you can import dialog box resources ---- ----- One sentence: It can be deleted from the resource) from the program framework; of course, you can also have reserved deletion, such as left the DLG resource, only delete resources such as BMP.

(3) When you delete resources in XXAPP, check the resource.h file added to the XXDLL program, copy all the things in the file (Alt A And Alt C). Open the resource.h paste (Alt V) of your XXAPP program (Ctrl S).

(4) Add a xxx.cpp file in your XXDLL empty project. The newly built DLL main function is as follows:

#include

Extern "C" BOOL WINAPI DLLMAIN (Hinstance Hinstance, DWORD DWREASON, LPVOID) {Return 1;}

(5) In the newly established DLL project. In the Project menu item, select Settings and select Project Settings' LINK Tags; then enter / noentry in the Project Options box. After compiling, a pure resource DLL file is generated;

The pure resource DLL file is added to the MDI or SDI program without any resource, which steps are as follows:

Load resource DLL

(1) Define protected Hinstance type variables (such as: m_hinst) in the main application class .h file;

(2) Add the following code from the .CPP file :: InitInstance () function procedure:

m_hinst = :: loadLibrary ("image.dll"); // image.dll DLL file for multi-language pure resources

IF (m_hinst == null)

{

Return false; // Load resource failed

}

Else {// Successfully load resources

// After the resource is loaded, you can use the AFXSetResourceHandle (pure resource DLL sentence prop) in the resource DLL

// Replace the resource ID in your program so that the resource ID used in your program is the resource ID in the resource DLL.

AFXSetResourceHandle (M_HINST); // Get Resources from the dll}

Release Resource DLL

Add the following code from the.cpp file :: exitInstance () function procedure:

Freelibrary (m_hinst); // Remember to release

转载请注明原文地址:https://www.9cbs.com/read-42633.html

New Post(0)