AccessResource

2.x

  int AccessResource(hinst, hrsrc)    
  HINSTANCE hinst; /* handle of module with resource */
  HRSRC hrsrc; /* handle of resource, */  

The AccessResource function opens the given executable file and moves the file pointer to the beginning of the given resource.

Parameters

hinst

Identifies the instance of the module whose executable file contains the resource.

hrsrc

Identifies the desired resource. This handle should be created by using the FindResource function.

Return Value

The return value is the handle of the resource file if the function is successful. Otherwise, it is –1.

Comments

The AccessResource function supplies an MS-DOS file handle that can be used in subsequent file-read calls to load the resource. The file is opened for reading only.

Applications that use this function must close the resource file by calling the _lclose function after reading the resource. AccessResource can exhaust available MS-DOS file handles and cause errors if the opened file is not closed after the resource is accessed.

In general, the LoadResource and LockResource functions are preferred. These functions will access the resource more quickly if several resources are being read, because Windows maintains a file-handle cache for accessing executable files. However, each call to AccessResource requires that a new handle be opened to the executable file.

You should not use AccessResource to access executable files that are installed in ROM on a ROM-based system, since there are no disk files associated with the executable file; in such a case, a file handle cannot be returned.

See Also

FindResource, _lclose, LoadResource, LockResource