Using the Resource

After the resource file (.RES) is created, there are two ways to use it within a subclassing application in VB. The first way is to simply add the resource file to the application. The second way is to add the resource file to a DLL and load the resource from this DLL. There is a reason for using each method to incorporate a resource into a project. If an application is running in the IDE at design time, the resource must be in a DLL. When the application is running as a standalone EXE, the resource can be embedded into the EXE as a .RES file, or it can be contained within a DLL. This is a limitation of VB, not of the resource file.

No other application can access the dialog template resource if it is embedded within this application as a .RES file because they are running in separate processes. Placing a resource in a separate DLL allows multiple applications to access the same resources. A single application also can access multiple resource DLLs.

VB has three functions for loading and using resources: LoadResString, LoadResData, and LoadResPicture. Although LoadResString and LoadResPicture are functions that load particular kinds of data (strings and images, respectively) from resource files, LoadResData is a general-purpose function for retrieving items from resource files. Its syntax is:

LoadResData(resID, resType)

where resID is the identifier of the resource, and resType is an integer that identifies the type of resource that’s being loaded. To load ...

Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.