I'm doing some interop with the PKCS11 Cryptoki interface. In summary, there
is a function which takes a c-style array (block of contiguously allocated
memory). When my interop definition is just for a single element everything is
fine. When I define the function as taking the required array, the details are
not received correctly by the DLL even in the basic case of a single element.
Here are the details in depth:
There is one function, C_GetAttributeValue which is defined in a C header file:
C_GetAttributeValue
(
CK_SESSION_HANDLE hSession, /* the session's handle */
CK_OBJECT_HANDLE hObject, /* the object's handle */
CK_ATTRIBUTE_PTR pTemplate, /* specifies attrs; gets vals */
CK_ULONG ulCount /* attributes in template */
);
The CK_ATTRIBUTE_PTR is the problem.
typedef struct CK_ATTRIBUTE {
CK_ATTRIBUTE_TYPE type;
CK_VOID_PTR pValue; /* ulValueLen went from CK_USHORT to CK_ULONG for
v2.0 */
CK_ULONG ulValueLen; /* in bytes */
} CK_ATTRIBUTE;
typedef CK_ATTRIBUTE CK_PTR CK_ATTRIBUTE_PTR;
Here are my definitions:
[StructLayout(LayoutKind.Sequential)]
public class CK_ATTRIBUTE_WRAPPED
{
public CK_ATTRIBUTE_WRAPPED()
{
}
public CK_ATTRIBUTE_WRAPPED(uint type, IntPtr pValue, uint ulCount)
{
this.type = type; this.pValue = pValue; this.ulCount = ulCount;
}
public uint type;
public IntPtr pValue;
public uint ulCount;
}
[DllImport("gclib.dll", EntryPoint = "C_GetAttributeValue")]
public unsafe static extern CK_RESULTS Wrapped_C_GetAttributeValue(uint
hSession, uint hObject, [Out, In] CK_ATTRIBUTE_WRAPPED pTemplate, int ulCount);
Everything works fine with the above definitions if I am just passing in a
single value. If I change the definition to be an array CK_ATTRIBUTE_WRAPPED[]
then even my single value test which works before now no longer works.
[DllImport("gclib.dll", EntryPoint = "C_GetAttributeValue")]
public unsafe static extern CK_RESULTS Wrapped_C_GetAttributeValue(uint
hSession, uint hObject, [Out, In] CK_ATTRIBUTE_WRAPPED[] pTemplate, int
ulCount);
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com