I am new to C#, Please help me with below case.
I am trying to import C++ dll into my C# Code and I am getting the following error.
A call to PInvoke function 'SerialInterface!SerialInterface.Form1::ReadTagData' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Below is the C# code
const int buffSize = 33;
const int addr = 112;
const int readBytes = 8;
[DllImport(@"C:\Visual Studio 2010\Projects\SerialInterface\SerialInterface\bin\Debug\AP4600_SDK.dll")]
public static extern int ReadTagData(string tagID, string tagBuffer, Int32 szTagDataBuf, Int32 TagAddress, Int32 nBytes);
string asciiRead = "";
int s = ReadTagData(TagId, asciiRead, buffSize, addr, readBytes);
The function ReadTagData
definition in the AP4600_SDK.dll is
AP4600_SDK_API int ReadTagData(
const char *pTagId, /* TagId of tag to be read, from Identify */
char *pTagDataBuf, /* (Output) The data read (ASCII representation of HEX), min size is 2*nBytes+1 (33 for Allegro) */
size_t szTagDataBuf, /* Size of TagDataBuf, minimum is 2*nBytes+1 (33 for Allegro) */
int TagAddress, /* Address of first byte to read */
size_t nBytes /* Number of bytes to read (between 1 and 8, inclusive) */
); /* Returns zero for success, non zero failure */