Jump to content

DosQueryProcAddr: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
DosQueryProcAddr is used to find the address of a process in a dynamic link module. Returns the address of the specified procedure within a dynamic link module.  
DosQueryProcAddr is used to find the address of a process in a dynamic link module. Returns the address of the specified procedure within a dynamic link module.


==Syntax==
==Syntax==
<PRE>
  DosQueryProcAddr(hmod, ordinal, pszName, ppfn)
HMODULE  hmod;    /* The handle of the dynamic link module that contains the procedure. */
ULONG    ordinal;  /* The ordinal number of the procedure whose address is desired. */
PSZ      pszName; /* The address of an ASCIIZ name string that contains the procedure name
                      that is being referenced. */
PFN      *ppfn;    /* A pointer to a PFN in which the procedure address is returned. */
APIRET    ulrc;    /* Return Code. */
 
ulrc = DosQueryProcAddr(hmod, ordinal, pszName, ppfn);
</PRE>


===Parameters===
===Parameters===
;hmod (HMODULE) - input : The handle of the dynamic link module that contains the procedure. (from DosLoadModule)
;hmod (HMODULE) - input:The handle of the dynamic link module that contains the procedure. (from DosLoadModule)
;ordinal (ULONG) - input: The ordinal number of the procedure whose address is desired.
;ordinal (ULONG) - input: The ordinal number of the procedure whose address is desired. If the ordinal number is nonzero, pszName is ignored. It must be less or equal to 65 533. (Ordinal number for the sought process. If 0 then ''pszProcName'' is used.)
If the ordinal number is nonzero, pszName is ignored. It must be less or equal to 65 533. (Ordinal number for the sought process. If 0 then ''pszProcName'' is used.)
;pszName (PSZ) - input:  The address of an ASCIIZ name string that contains the procedure name that is being referenced.
;pszName (PSZ) - input:  The address of an ASCIIZ name string that contains the procedure name that is being referenced.
:Calls to DosQueryProcAddr for entries within the DOSCALLS module are supported for ordinal references only. References to the DOSCALLS module by name strings are not supported, and will return an error. Dynamic link ordinal numbers for DOSCALLS routines are resolved by linking with OS2386.LIB. (Pointer to string containing the sought processes name. Not case sensitive.)
:Calls to DosQueryProcAddr for entries within the DOSCALLS module are supported for ordinal references only. References to the DOSCALLS module by name strings are not supported, and will return an error. Dynamic link ordinal numbers for DOSCALLS routines are resolved by linking with OS2386.LIB. (Pointer to string containing the sought processes name. Not case sensitive.)
Line 22: Line 12:


===Returns===
===Returns===
; APIRET rc
;APIRET rc: Indicates if any error occurred.
: Indicates if any error occured.  
{|class="wikitable"
{|class="wikitable"
|0|| NO_ERROR
|0|| NO_ERROR
Line 43: Line 32:
If you receive return code ERROR_INVALID_HANDLE, issue DosLoadModule and repeat this call.
If you receive return code ERROR_INVALID_HANDLE, issue DosLoadModule and repeat this call.


If you issue DosQueryProcAddr to obtain the address of an entry point that may only be accessed via a call gate, you receive the return code ERROR_ENTRY_IS_CALLGATE.  
If you issue DosQueryProcAddr to obtain the address of an entry point that may only be accessed via a call gate, you receive the return code ERROR_ENTRY_IS_CALLGATE.


==Sample Code==
==Sample Code==
Line 69: Line 58:
  #include <stdio.h>
  #include <stdio.h>


int main(VOID) {
int main(VOID) {


  PSZ      ModuleName    = "C:\\OS2\\DLL\\DISPLAY.DLL";  /* Name of module  */
  PSZ      ModuleName    = "C:\\OS2\\DLL\\DISPLAY.DLL";  /* Name of module  */

Latest revision as of 23:07, 2 July 2019

DosQueryProcAddr is used to find the address of a process in a dynamic link module. Returns the address of the specified procedure within a dynamic link module.

Syntax

DosQueryProcAddr(hmod, ordinal, pszName, ppfn)

Parameters

hmod (HMODULE) - input
The handle of the dynamic link module that contains the procedure. (from DosLoadModule)
ordinal (ULONG) - input
The ordinal number of the procedure whose address is desired. If the ordinal number is nonzero, pszName is ignored. It must be less or equal to 65 533. (Ordinal number for the sought process. If 0 then pszProcName is used.)
pszName (PSZ) - input
The address of an ASCIIZ name string that contains the procedure name that is being referenced.
Calls to DosQueryProcAddr for entries within the DOSCALLS module are supported for ordinal references only. References to the DOSCALLS module by name strings are not supported, and will return an error. Dynamic link ordinal numbers for DOSCALLS routines are resolved by linking with OS2386.LIB. (Pointer to string containing the sought processes name. Not case sensitive.)
ppfn (PFN *) - output
A pointer to a PFN in which the procedure address is returned. (Address of a function pointer, which will contain the address of the procedure.)

Returns

APIRET rc
Indicates if any error occurred.
0 NO_ERROR
6 ERROR_INVALID_HANDLE
123 ERROR_INVALID_NAME
182 ERROR_INVALID_ORDINAL
65079 ERROR_ENTRY_IS_CALLGATE

Include Info

#define INCL_DOSMODULEMGR
#include <os2.h>

Remarks

If you receive return code ERROR_INVALID_HANDLE, issue DosLoadModule and repeat this call.

If you issue DosQueryProcAddr to obtain the address of an entry point that may only be accessed via a call gate, you receive the return code ERROR_ENTRY_IS_CALLGATE.

Sample Code

void (* my_dll_function)(int, char*);  /* Pointer to process */
HMODULE hmod;
APIRET rc = 0;

/* Load DLL and get hmod with DosLoadModule*/ 

/* Get address for process in DLL */
rc = DosQueryProcAddr(hmod, 0, "MY_DLL_FUNCTION", (PFN *) my_dll_function);
if(rc) {   /* Failure? */
   printf("Error. Cannot get the address for my_dll_function. DosQueryProcAddr returned %d.\n",rc);
   return(-1);
}

/* Call my_dll_function */
my_dll_function(4711,"Hello World!\n");

This example loads the dynamic link module "DISPLAY.DDL", queries its address and type, and finally frees it.

 #define INCL_DOSMODULEMGR     /* Module Manager values */
 #define INCL_DOSERRORS        /* Error values */
 #include <os2.h>
 #include <stdio.h>

 int main(VOID) {

 PSZ      ModuleName     = "C:\\OS2\\DLL\\DISPLAY.DLL";  /* Name of module   */
 UCHAR    LoadError[256] = "";          /* Area for Load failure information */
 HMODULE  ModuleHandle   = NULLHANDLE;  /* Module handle                     */
 PFN      ModuleAddr     = 0;           /* Pointer to a system function      */
 ULONG    ModuleType     = 0;           /* Module type                       */
 APIRET   rc             = NO_ERROR;    /* Return code                       */

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

   rc = DosQueryProcAddr(ModuleHandle,         /* Handle to module           */
                         1L,                   /* No ProcName specified      */
                         NULL,                 /* ProcName (not specified)   */
                         &ModuleAddr);         /* Address returned           */
   if (rc != NO_ERROR) {
      printf("DosQueryProcAddr error: return code = %u\n", rc);
      return 1;
   } else printf("Address of module is 0x%x.\n", ModuleAddr);

   rc = DosQueryProcType(ModuleHandle,         /* Handle to module           */
                         1L,                   /* Indicate no ProcName given */
                         NULL,                 /* ProcName (not specified)   */
                         &ModuleType);         /* Type 0=16-bit   1=32-bit   */
   if (rc != NO_ERROR) {
      printf("DosQueryProcType error: return code = %u\n", rc);
      return 1;
   } else printf("This is a %s module.\n", ( ModuleType ? "32-bit" : "16-bit"));

   rc = DosFreeModule(ModuleHandle);
   if (rc != NO_ERROR) {
      printf("DosFreeModule error: return code = %u\n", rc);
      return 1;
   } else printf("Module %s freed.\n", ModuleName);

   return NO_ERROR;
}

See Also