Next: Signal Handling, Previous: Using Libtool, Up: Preparation
The function
gpgme_check_version
has three purposes. It can be used to retrieve the version number of the library. In addition it can verify that the version number is higher than a certain required version number. In either case, the function initializes some sub-systems, and for this reason alone it must be invoked early in your program, before you make use of the other functions in GPGME.As a side effect for W32 based systems, the socket layer will get initialized.
If required_version is
NULL
, the function returns a pointer to a statically allocated string containing the version number of the library.If required_version is not
NULL
, it should point to a string containing a version number, and the function checks that the version of the library is at least as high as the version number provided. In this case, the function returns a pointer to a statically allocated string containing the version number of the library. If REQUIRED_VERSION is not a valid version number, or if the version requirement is not met, the function returnsNULL
.If you use a version of a library that is backwards compatible with older releases, but contains additional interfaces which your program uses, this function provides a run-time check if the necessary features are provided by the installed version of the library.
After initializing GPGME, you should set the locale information to the locale required for your output terminal. This locale information is needed for example for the curses and Gtk pinentry. Here is an example of a complete initialization:
#include <locale.h> #include <gpgme.h> void init_program (void) { /* Initialize the locale environment. */ setlocale (LC_ALL, ""); gpgme_check_version (NULL); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); #ifdef LC_MESSAGES gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif }
Note that you are highly recommended to initialize the locale settings like this. GPGME can not do this for you because it would not be thread safe. The conditional on LC_MESSAGES is only necessary for portability to W32 systems.