1

I am trying to make a plugin system all by using Delphi XE2 via the Firemonkey framework. The issue is that I am getting the error GetProcAddress is undeclared identifier. When I attempt to use GetProcAddress in a VCL project everything works fine, so what is the difference between VCL and Firemonkey when talking about GetProcAddress and how to use it in a Firemonkey App.

Thanks

Johan
  • 74,508
  • 24
  • 191
  • 319

3 Answers3

4

When you compile the application for Windows, use Winapi.Windows.GetProcAddress. If not, use System.SysUtils.GetProcAddress. The uses clause in that case should look like this:

uses
{$IFDEF MSWINDOWS}
  Winapi.Windows,
{$ENDIF}
  System.SysUtils;
Stefan Glienke
  • 20,860
  • 2
  • 48
  • 102
  • +1 Didn't know that Mac had the same procedure :-) Note that the actual call to `GetProcAddress` in MacOS is different from Windows, so you'll need a define there as well. – Johan Mar 16 '12 at 20:09
3

GetProcAddress is a Windows API system call.
For this reason it has no place in a cross platform FMX application.

If you only want you app to run on Windows, you can add the unit where GetProcAddress is defined to the uses clause.

From: http://docwiki.embarcadero.com/RADStudio/en/Libraries_and_Packages

add Windows to the uses clause.

what is the difference between VCL and Firemonkey when talking about GetProcAddress

The VCL is bound specifically to Windows, Firemonkey (aka FMX) is made to be cross platform and for this reason does not add windows to its default uses clause.

Johan
  • 74,508
  • 24
  • 191
  • 319
  • docwiki says that there is `System.SysUtils.GetProcAddress()` (http://docwiki.embarcadero.com/RADStudio/en/Cross-Platform_Shared_Libraries).. but I can't find it here -> http://docwiki.embarcadero.com/Libraries/en/System.SysUtils – teran Mar 16 '12 at 14:16
  • @teran, see the link in the answer, it says literally: `You can access routines in a library through direct calls to Win32 APIs, including LoadLibrary, FreeLibrary, and GetProcAddress. These functions are declared in Windows.pas. In this case, use procedural-type variables to reference the imported routines.` – Johan Mar 16 '12 at 14:20
  • @teran looks like a documentation error in the DocWiki page about Cross-Platform Shared Libraries – mjn Mar 16 '12 at 15:39
  • @mjn anyway there is an `GetProcAddress` in `System.SysUtils` with next comment: `{ GetProcAddress does what it implies. It performs the same function as the like named function under Winapi.Windows. dlsym does not quite have the same sematics as GetProcAddress as it will return the address of a symbol in another module if it was not found in the given HMODULE. This function will verify that the 'Proc' is actually found within the 'Module', and if not returns nil }` – teran Mar 16 '12 at 18:03
  • so. for windows we have to use `winapi.windows.getProcAddress` and for mac - `sysUtils.getProcAddress` as @Stefan Glienke wrote in his answer. – teran Mar 16 '12 at 18:10
0

On OS X, neither the Loadlibray nor GetProcaddress function is defined in the sysutils - both functions are exclusively included in a POSIX definition.