in our VO app, we were using a C dll for encryption/decryption
The ported code seemto crash when calling the dll.
We do have the source code of the C dll so I tried to see what was bother the Xsharp version of the code :
Code: Select all
#define BF_LONG unsigned long
#define BF_ROUNDS 16
typedef struct bf_key_st
{
BF_LONG P[BF_ROUNDS+2];
BF_LONG S[4*256];
} BF_KEY;
typedef BF_KEY PCRYPT_CTX;
void PCryptInit(PCRYPT_CTX *ctx, unsigned char *key, int count)
{
BF_set_key(ctx, count, key);
return;
}
Code: Select all
_DLL FUNCTION PCryptInit(ctx AS PCRYPT_CTX, key PSZ, count AS INT) AS VOID PASCAL:PgsUti32.PCryptInit
VOSTRUCT PCRYPT_CTX
MEMBER DIM P[16+2] AS DWORD
MEMBER DIM S[4*256] AS DWORD
A call to PInvoke function has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature.
So I tried to match the signature "closer"
Code: Select all
_DLL FUNCTION PCryptInit(ctx AS PCRYPT_CTX, key AS BYTE[], count AS INT) AS VOID PASCAL:PgsUti32.PCryptInit
USING System.Runtime.InteropServices
[StructLayout(LayoutKind.Sequential)];
PUBLIC CLASS PCRYPT_CTX
PUBLIC DIM P[16+2] AS DWORD
PUBLIC DIM S[4*256] AS DWORD
END CLASS
LOCAL ctx AS PCRYPT_CTX
LOCAL bKey AS BYTE[]
bKey := BYTE[]{16}{235,89,56,22,81,127,158,80,216,87,210,149,134,206,99,129}
PCryptInit(ctx, bKey, bKey:Length)
Any suggestion ?