Use a custom resource in a VC project

Source: Internet
Author: User
Tags pack resource

First, the preface

In addition to the standard resource types, such as dialog, menu, and bitmap, which are commonly used in VC environments, it also supports custom resource types (custom Resource), what can we do with our custom resource types? Oh, use a lot.

The default skin compression package or language pack. Some support for skin-changing software especially some media players often have custom skins files (you can try to put media Players or thousands of listening software in the skins directory of the file extension to. zip, and then use the WinZip open to look at it, but in order to prevent skin file loss caused the software can not be displayed, they often in the EXE file built-in set of skin as the default skin file. Similarly, there is the default language pack in some EXE files that support multiple languages (you can also use the String Table resource type);

As a parasitic way of some virus/trojan program. If you accidentally execute a virus/Trojan program, they will release the virus/Trojan file when you run. Of course, many viruses are written to their own PE file header to achieve;

Merge the EXE with the DLL file it needs. For some reason program authors may sometimes need to embed DLL files into executable exe files, which can be achieved by using custom resources;

Other need to play an AVI animation in the program, etc., can be implemented by adding binary data files as custom resources to executable files;

Second, add

When adding resources, choose Custom, the IDE will generate a new binary resource for you, and then you can import your existing binaries into your project as a custom resource type.

Third, the use

To use a custom resource, several API functions that we might use include FindResource, LoadResource, and Lockresource, where the return value of each function is the parameter of the next function, which I would like to briefly introduce.

FindResource is used to locate the specified resource in a specified module:

HRSRC FindResource(
HMODULE hModule,    //包含所需资源的模块句柄,如果是程序本身,可以置为NULL
LPCTSTR lpName,    //可以是资源名称或资源ID
LPCTSTR lpType    //资源类型,在这里也就是我们自己指定的资源类型
);

LoadResource is used to load the specified resource into memory;

HGLOBAL LoadResource(
HMODULE hModule,    //模块句柄,同上
HRSRC hResInfo    //需要加载的资源句柄,这里也就是FindResource的返回值
);

Lockresource is used to lock in-memory resource blocks, and its return value is the memory pointer to the resource data that we want to use;

LPVOID LockResource(
HGLOBAL hResData    //指向内存中要锁定的资源数据块,这里也就是LoadResource的返回值
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.