I run managed code and initiate an unmanaged code call. There is a callback in unmanaged code. From unmanaged, I get a callback in my managed method "DelegateMethod". But I am not getting the correct parameter / argument values from unmanaged code. Please help me with this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace TestApp
{
public class Program
{
public delegate void fPointer(byte[] Sendapdu, ref int Sendlen, byte[] Recvapdu, ref int Recvlen);
public struct sCommsAbstraction
{
public fPointer pf_TxRx;
}
public static void DelegateMethod(byte[] Sendapdu, ref int Sendlen, byte[] Recvapdu, ref int Recvlen)
{
Console.WriteLine(Sendlen);
}
[DllImport("AuthLibrary.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int CmdLib_RegisterItsIO(ref sCommsAbstraction psCommsFunctions);
[DllImport("AuthLibrary.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int CmdLib_OpenApplication();
[DllImport("TransparentChannel.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int TC_Transceive(byte[] writeBuf, ref int writeBufLen, byte[] readBuf, ref int pwReadBufferLen);
static void Main(string[] args)
{
sCommsAbstraction psCommsFunctions = new sCommsAbstraction();
psCommsFunctions.pf_TxRx = DelegateMethod;
CmdLib_RegisterItsIO(ref psCommsFunctions);
CmdLib_OpenApplication();
}
}
}
Here is my indispensable piece of code - CmdLib.c
typedef int32_t (*pFTransceive)(const uint8_t *prgbWriteBuffer, const uint16_t *pwWriteBufferLen, uint8_t *prgbReadBuffer, uint16_t *pwReadBufferLen);
typedef struct sCommsAbstraction
{
pFTransceive pf_TxRx;
}sCommsAbstraction_d
static sCommsAbstraction_d sCommsAbstraction = {0};
void CmdLib_RegisterItsIO(const sCommsAbstraction_d *psCommsFunctions)
{
sCommsAbstraction.pf_TxRx = psCommsFunctions->pf_TxRx;
}
void CmdLib_OpenApplication()
{
sCommsAbstraction.pf_TxRx(rgbAPDUBuffer,&wTotalLength,rgbAPDUBuffer,&psApduData->wResponseLength);
}
source
share