xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

GetProcAddress()

Retrieves the memory address of a function in a dynamically loaded DLL.

Syntax

GetProcAddress( <nDllHandle>, ;
                <cFuncName>|<nOrdinal> ) --> pAddress

Arguments

<nDllHandle>
This is a numeric handle of the DLL that contains the DLL function. It is the return value of LoadLibrary().
<cFuncName>
This is a character string holding the symbolic name of the function to obtain the memory address for. Unlike regular xHarbour functions, this function name is case sensitive.
<nOrdinal>
Instead of the symbolic function name, the numeric ordinal position of the function inside the DLL file can be passed.

Return

The function returns the memory address of <cFuncName> as a pointer. When the function cannot be found in the DLL, a null pointer is returned.

Description

Function GetProcAddress() obtains the memory address of a DLL function after the DLL is loaded into memory with LoadLibrary(). The memory address of a function, also called function pointer, is sometimes required by API functions when they need to call other functions.

Note:  the pointer returned by GetProcAddress() can be passed to function CallDll() which executes the function.

Info

See also:CallDll(), DllCall(), DllPrepareCall(), LoadLibrary()
Category: DLL functions , xHarbour extensions
Source:rtl\dllcall.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates case sensitivity of function names
// with DLL functions.

   PROCEDURE Main
      LOCAL nDll := LoadLibrary( "Kernel32.dll" )

      ? GetProcAddress( nDll, "MultiByteToWideChar" )  // result: 7c809cad

      ? GetProcAddress( nDll, "MultibyteToWideChar" )  // result: 00000000

      FreeLibrary( nDll )
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe