[Mono-list] Catching C-callbacks through InteropServices
Simon Ask Ulsnes
Fri, 28 May 2004 20:14:22 +0200
I'm writing a GnuPG interface for Mono/.NET using GPGME (GnuPG Made
Easy, which is the C API applications use for connecting with gpg).
So far, it works fine, I can retrieve keys and encrypt/sign. However,
the GPGME API is constructed in such a way that in order to retrieve a
passphrase for use with decryption, you have to give it a callback
function returning the passphrase as a const char*.
What I would do is to make a property in my GnuPGEngine class (which
manages communication with the C layer through InteropServices) which
will then be given to the real GnuPG engine (a GpgmeCtx, which means a
GPGME Context object) through an internal callback.
How is this best done?
The API syntax in C for setting the callback function for the context is:
gpgme_set_passphrase(ctx, &get_passphrase, NULL);
static const char* get_passphrase(void *HOOK, const char *DESC, void
With the above, the get_passphrase function never gets called. What to do?