Jump to content

DosQueryResourceSize: Difference between revisions

From EDM2
Created page with "==Description== ==Syntax== <PRE> </PRE> ==Parameters== ; hmod (HMODULE) - input : The handle of the module that has the required resource. A value of zero means to get the..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Description==
DosQueryResourceSize returns the size of the specified resource object.


Resource objects are read-only data objects that can be accessed dynamically at run time. The access key is two numbers. The first number is a type ID; the second, a name ID. These are similar to the file-extension and file-name portions of a file name.
Resource objects are placed into an executable file by the [[Resource Compiler]] (RC.EXE).
This function obtains the size of resources loaded from 16-bit executable files or dynamic link libraries (DLLs), since the size is not explicitly stored in most resources.


==Syntax==
==Syntax==
<PRE>
DosQueryResourceSize (hmod, idt, idn, pulsize)


</PRE>
==Parameters==
==Parameters==
; hmod (HMODULE) - input : The handle of the module that has the required resource.
;hmod (HMODULE) - input: The handle of the module that has the required resource.
:A value of zero means to get the size from the current process. A value other than zero is a module handle that was returned by [[DosLoadModule]].
;idt (ULONG) - input: The type identifier of the resource.
:Possible values are between 1 and 0xFFFE inclusive. Values from 1 to 255 are reserved for predefinition. Values from 256 and on can be type defined for the resource. The fist 21 values are predefined as follows:
:#RT_POINTER Mouse pointer shape
:#RT_BITMAP Bit map
:#RT_MENU Menu template
:#RT_DIALOG Dialog template
:#RT_STRING String tables
:#RT_FONTDIR Font directory
:#RT_FONT Font
:#RT_ACCELTABLE Accelerator tables
:#RT_RCDATA Binary data
:#RT_MESSAGE Error message tables
:#RT_DLGINCLUDE Dialog include file name
:#RT_VKEYTBL Key to vkey tables
:#RT_KEYTBL Key to UGL tables
:#RT_CHARTBL Glyph to character tables
:#RT_DISPLAYINFO Screen display information
:#RT_FKASHORT Function key area short form
:#RT_FKALONG Function key area long form
:#RT_HELPTABLE Help table for Help manager
:#RT_HELPSUBTABLE Help subtable for Help manager
:#RT_FDDIR DBCS unique/font driver directory
:#RT_FD DBCS unique/font driver
;idn (ULONG) - input : The name identifier of the resource.
:Possible values are between 1 and 0xFFFE inclusive.
;pulsize (PULONG) - output: A pointer to a ULONG in which the size, in bytes, of the resource is returned.


A value of zero means to get the size from the current process. A value other than zero is a module handle that was returned by DosLoadModule.
===Return Code===
;ulrc (APIRET) - returns:DosQueryResourceSize returns one of the following values:
*0 NO_ERROR
*6 ERROR_INVALID_HANDLE
*87 ERROR_INVALID_PARAMETER


; idt (ULONG) - input : The type identifier of the resource.
==Example Code==
This example loads the dynamic link module "DISPLAY.DLL", and queries the size of the font directory id=1 resource.
<PRE>
#define INCL_DOSRESOURCES    /* Resource types */
#define INCL_DOSMODULEMGR    /* Module Manager values */
#define INCL_DOSERRORS        /* DOS error values */
#include <os2.h>
#include <stdio.h>


Possible values are between 1 and 0xFFFE inclusive. Values from 1 to 255 are reserved for predefinition. Values from 256 and on can be type defined for the resource. The fist 21 values are predefined as follows:
int main(VOID) {
UCHAR    LoadError[256] = "";            /* Area for Load failure information */
PSZ      ModuleName = "C:\\OS2\\DLL\\PMWP.DLL";  /* DLL with resources */
HMODULE  ModHandle  = NULLHANDLE;        /* Handle for module */
ULONG    Size      = 0;                /* Resource size */
APIRET    rc        = NO_ERROR;          /* API return code */


     1 RT_POINTER
rc = DosLoadModule(LoadError,              /* Failure information buffer */
    Mouse pointer shape
                    sizeof(LoadError),      /* Size of buffer            */
                    ModuleName,              /* Module to load            */
                    &ModHandle);            /* Module handle returned     */
if (rc != NO_ERROR) {
    printf("DosLoadModule error: return code = %u\n", rc);
    return 1;
}


     RT_BITMAP
rc = DosQueryResourceSize(ModHandle,     /* Handle for DLL containing resources */
    Bit map
                          RT_POINTER,    /* Ask for  Pointer                    */
                          1L,            /*          with an ID of 1            */
                          &Size);        /* The resource size is returned.      */


     RT_MENU
if (rc != NO_ERROR) {
     Menu template
     printf("DosGetResource error: return code = %u\n", rc);
     return 1;
} else {
    printf("Resource is %u bytes in size.\n", Size);
} /* endif */


    RT_DIALOG
return NO_ERROR;
    Dialog template
}
 
</PRE>
    RT_STRING
    String tables
 
    RT_FONTDIR
    Font directory
 
    RT_FONT
    Font


    RT_ACCELTABLE
    Accelerator tables
    RT_RCDATA
    Binary data
    10
        RT_MESSAGE
        Error message tables 11
        RT_DLGINCLUDE
        Dialog include file name 12
        RT_VKEYTBL
        Key to vkey tables 13
        RT_KEYTBL
        Key to UGL tables 14
        RT_CHARTBL
        Glyph to character tables 15
        RT_DISPLAYINFO
        Screen display information 16
        RT_FKASHORT
        Function key area short form 17
        RT_FKALONG
        Function key area long form 18
        RT_HELPTABLE
        Help table for Help manager 19
        RT_HELPSUBTABLE
        Help subtable for Help manager 20
        RT_FDDIR
        DBCS unique/font driver directory 21
        RT_FD
        DBCS unique/font driver
    idn (ULONG) - input
        The name identifier of the resource.
        Possible values are between 1 and 0xFFFE inclusive.
    pulsize (PULONG) - output
        A pointer to a ULONG in which the size, in bytes, of the resource is returned.
==Return Code==
==Remarks==
==Example Code==
<PRE>
</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:
*[[DosFreeResource]]
 
*[[DosGetResource]]
*[[DosLoadModule]]


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 18:40, 29 August 2021

DosQueryResourceSize returns the size of the specified resource object.

Resource objects are read-only data objects that can be accessed dynamically at run time. The access key is two numbers. The first number is a type ID; the second, a name ID. These are similar to the file-extension and file-name portions of a file name.

Resource objects are placed into an executable file by the Resource Compiler (RC.EXE).

This function obtains the size of resources loaded from 16-bit executable files or dynamic link libraries (DLLs), since the size is not explicitly stored in most resources.

Syntax

DosQueryResourceSize (hmod, idt, idn, pulsize)

Parameters

hmod (HMODULE) - input
The handle of the module that has the required resource.
A value of zero means to get the size from the current process. A value other than zero is a module handle that was returned by DosLoadModule.
idt (ULONG) - input
The type identifier of the resource.
Possible values are between 1 and 0xFFFE inclusive. Values from 1 to 255 are reserved for predefinition. Values from 256 and on can be type defined for the resource. The fist 21 values are predefined as follows:
  1. RT_POINTER Mouse pointer shape
  2. RT_BITMAP Bit map
  3. RT_MENU Menu template
  4. RT_DIALOG Dialog template
  5. RT_STRING String tables
  6. RT_FONTDIR Font directory
  7. RT_FONT Font
  8. RT_ACCELTABLE Accelerator tables
  9. RT_RCDATA Binary data
  10. RT_MESSAGE Error message tables
  11. RT_DLGINCLUDE Dialog include file name
  12. RT_VKEYTBL Key to vkey tables
  13. RT_KEYTBL Key to UGL tables
  14. RT_CHARTBL Glyph to character tables
  15. RT_DISPLAYINFO Screen display information
  16. RT_FKASHORT Function key area short form
  17. RT_FKALONG Function key area long form
  18. RT_HELPTABLE Help table for Help manager
  19. RT_HELPSUBTABLE Help subtable for Help manager
  20. RT_FDDIR DBCS unique/font driver directory
  21. RT_FD DBCS unique/font driver
idn (ULONG) - input
The name identifier of the resource.
Possible values are between 1 and 0xFFFE inclusive.
pulsize (PULONG) - output
A pointer to a ULONG in which the size, in bytes, of the resource is returned.

Return Code

ulrc (APIRET) - returns
DosQueryResourceSize returns one of the following values:
  • 0 NO_ERROR
  • 6 ERROR_INVALID_HANDLE
  • 87 ERROR_INVALID_PARAMETER

Example Code

This example loads the dynamic link module "DISPLAY.DLL", and queries the size of the font directory id=1 resource.

#define INCL_DOSRESOURCES     /* Resource types */
#define INCL_DOSMODULEMGR     /* Module Manager values */
#define INCL_DOSERRORS        /* DOS error values */
#include <os2.h>
#include <stdio.h>

int main(VOID) {
UCHAR     LoadError[256] = "";            /* Area for Load failure information */
PSZ       ModuleName = "C:\\OS2\\DLL\\PMWP.DLL";  /* DLL with resources */
HMODULE   ModHandle  = NULLHANDLE;        /* Handle for module */
ULONG     Size       = 0;                 /* Resource size */
APIRET    rc         = NO_ERROR;          /* API return code */

 rc = DosLoadModule(LoadError,               /* Failure information buffer */
                    sizeof(LoadError),       /* Size of buffer             */
                    ModuleName,              /* Module to load             */
                    &ModHandle);             /* Module handle returned     */
 if (rc != NO_ERROR) {
    printf("DosLoadModule error: return code = %u\n", rc);
    return 1;
 }

 rc = DosQueryResourceSize(ModHandle,     /* Handle for DLL containing resources */
                           RT_POINTER,    /* Ask for  Pointer                    */
                           1L,            /*          with an ID of 1            */
                           &Size);        /* The resource size is returned.      */

 if (rc != NO_ERROR) {
    printf("DosGetResource error: return code = %u\n", rc);
    return 1;
 } else {
    printf("Resource is %u bytes in size.\n", Size);
 } /* endif */

return NO_ERROR;
}

Related Functions