C++ Class for fb_database_crypt_callback
This class can be compiled with Visual C++ and be used with C++Builder which lacks proper Template support.
Note
Note the loading of gds32.dll, normally the dll loaded would be fbclient.dll while the main application (because because its using IBX) will use gds32.dll.
Because we are using a global thread-local variable for legacy callback into the Firebird client we must make sure only one firebird client dll is loaded and that dll must be gds32.dll
Class:
CryptKey key; typedef ISC_STATUS(__stdcall *p_fb_database_crypt_callback)(ISC_STATUS*, void*); extern "C" int __declspec(dllexport) SetKey1(char *szkey, int len ) { ICryptKeyCallback* cb = &key; HMODULE hGDS32 = NULL; p_fb_database_crypt_callback pSetCallback = NULL; strncpy_s(szKey, szkey, len); szKey[len] = NULL; try { ISC_STATUS status; ISC_STATUS statusArray[20]; hGDS32 = LoadLibraryA("gds32.dll"); if(hGDS32==NULL) return -2; pSetCallback = (p_fb_database_crypt_callback)GetProcAddress(hGDS32, "fb_database_crypt_callback"); if (pSetCallback == NULL) throw "GetProcAddress error"; status = pSetCallback(statusArray, (void*)cb); char szMsg[64],szRet[16]; //strcpy_s(szMsg, "fb_database_crypt_callback returned "); //_itoa_s(status, szRet, 10); //strcat_s(szMsg,szRet); //MessageBoxA(NULL, szMsg, "SetColor", MB_OK); FreeLibrary(hGDS32); return (int)status; } catch (...) { if(hGDS32) FreeLibrary(hGDS32); return -1; } }