static LibraryUnix() { IntPtr module = dlopen("libekmpkcs11.so", RTLD_NOW); if (module == IntPtr.Zero) { throw new CKR_Exception(CK.CKR_FUNCTION_FAILED, "libekmpkcs11.so is not loaded"); } IntPtr ptr_C_GetFunctionList = dlsym(module, "C_GetFunctionList"); if (ptr_C_GetFunctionList == IntPtr.Zero) { throw new CKR_Exception(CK.CKR_FUNCTION_FAILED); } type_C_GetFunctionList C_GetFunctionList = (type_C_GetFunctionList)Marshal.GetDelegateForFunctionPointer(ptr_C_GetFunctionList, typeof(type_C_GetFunctionList)); IntPtr funcListPtr; CKR_Exception.check(C_GetFunctionList(out funcListPtr)); Marshal.PtrToStructure(funcListPtr, fl); }
static LibraryWindows() { IntPtr module = LoadLibrary("ekmpkcs11.dll"); if (module == IntPtr.Zero) { throw new CKR_Exception(CK.CKR_FUNCTION_FAILED); } IntPtr ptr_C_GetFunctionList = GetProcAddress(module, "C_GetFunctionList"); if (ptr_C_GetFunctionList == IntPtr.Zero) { throw new CKR_Exception(CK.CKR_FUNCTION_FAILED); } type_C_GetFunctionList C_GetFunctionList = (type_C_GetFunctionList)Marshal.GetDelegateForFunctionPointer(ptr_C_GetFunctionList, typeof(type_C_GetFunctionList)); IntPtr funcListPtr; CKR_Exception.check(C_GetFunctionList(out funcListPtr)); Marshal.PtrToStructure(funcListPtr, fl); }