×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Help:C#/Pinvoke

本文发表在 rolia.net 枫下论坛C++ .DLL .h file定义

typedef int (__stdcall* P_GETDATETIME)(unsigned char *ucDatetime);
typedef void (__stdcall* P_IOCTRL)(unsigned char ioname,unsigned char *piovalue);

typedef struct _FUNCPTR_PARAM_
{
P_GETDATETIME pGetDateTime;
P_IOCTRL pIoCtrl;
}FUNCPTR_PARAM;

__declspec(dllimport) int __stdcall EmvLib_Init(FUNCPTR_PARAM *ptrFunc);

在C# 中 要调用DLL EMVLib_Init

public delegate int P_GETDATETIME ([MarshalAs(UnmanagedType.LPStr)] StringBuilder ucDatetime);
public delegate void P_IOCTRL(byte ioname, [MarshalAs(UnmanagedType.LPStr)] StringBuilder piovalue);

[StructLayout(LayoutKind.Sequential)]
public struct FUNCPTR_PARAM
{
public P_GETDATETIME pGetDateTime;
public P_IOCTRL pIoCtrl;
}

[DllImport("EMV_CORE.dll")]
public extern static int EmvLib_Init(FUNCPTR_PARAM[] ptrFunc);

int cEmvLib_GetDateTime([MarshalAs(UnmanagedType.LPStr)] StringBuilder ucDatetime)
{
return 0; //for testing
}

void cEmvLib_IoCtrl(byte ioname, [MarshalAs(UnmanagedType.LPStr)] StringBuilder piovalue)
{
int debugI = 0; //for testing
}

void main()
{
FUNCPTR_PARAM g_stFuncPointer;
g_stFuncPointer.pGetDateTime = cEmvLib_GetDateTime;
g_stFuncPointer.pIoCtrl = cEmvLib_IoCtrl;

EmvLib_Init(new FUNCPTR_PARAM[]{stFuncPointer};
}

当执行上面EmvLib_Init 时出现了Out Of Memory Exception. 不知道问题出现咋哪里更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report