Mastering Android NDK
上QQ阅读APP看书,第一时间看更新

Dynamic linking on Windows platform

The libraries considered in this chapter can be built for Windows as dynamic link libraries. We do not provide recipes for doing this because each project already contains all the necessary instructions, and Windows development is not the focus of this book. The only exception is the libcurl and OpenSSL libraries. We recommend that you download the prebuilt DLL files from the official library site.

In the example code for FreeImage, FreeType, and Theora, we use function pointers, which are initialized using the GetProcAddress() and LoadLibrary() functions from WinAPI. The same function pointers are used on Android, but in this case, they point to appropriate functions from a static library.

For example, the function FreeImage_OpenMemory() is declared as follows:

typedef FIMEMORY* ( DLL_CALLCONV* PFNFreeImage_OpenMemory )
  ( void*, unsigned int );
PFNFreeImage_OpenMemory  FI_OpenMemory = nullptr;

On Windows, we initialize the pointer with the GetProcAddress() call:

FI_OpenMemory = (PFNFreeImage_OpenMemory)
  GetProcAddress (hFreeImageDLL,"FreeImage_OpenMemory");

On Android, OSX, and Linux, it is a redirection:

FI_OpenMemory = &FreeImage_OpenMemory;

The example code only refers to FI_OpenMemory(), and thus, is the same for both Android and Windows.