Problems with data types from an external dll

I am using Philip MfRc500.dll to communicate with RFID chips. It contains a function for reading data, which is defined as follows:

signed char Mf500PiccRead(unsigned char addr, unsigned char * data)

I use it in VB.NET as follows:

Private Declare Function RFID_PiccRead Lib "MfRc500.dll" Alias "_Mf500PiccRead@8" (ByVal addr As UShort, ByRef value As Long) As Short

and then wrapper:

Public Function PiccRead(ByVal addr As UShort, ByRef value As Long) As Short
    Return RFID_PiccRead(addr, value)
End Function

The second parameter in the Mf500PiccRead function can return a "16-byte data block", so my long data type is too small. If I use byte () instead of long, then I get ExecutionEngineException Exception.

What type of data should I use and how?

+3
source share
3 answers

- Byte(). ExecutionEngineException , . , , :

    Dim buffer(666) As Byte
    Dim retval As SByte = RFID_PiccRead(42, Buffer)
...
  Private Declare Function RFID_PiccRead Lib "MfRc500.dll" Alias "_Mf500PiccRead@8" _
     (ByVal addr As Byte, Byval buffer() As Byte) As SByte
+3

A char a Byte, .

PInvoke Interop Assistant C VB.Net PInvoke.

, . , , 16 , .

Private Declare Function RFID_PiccRead Lib "MfRc500.dll" _ 
  Alias "_Mf500PiccRead@8" (ByVal addr As Byte, ByRef value() As Byte) As Byte 

16- , , .

+1

try using Int or Integer instead of short.

Private declarative function RFID_PiccRead Lib "MfRc500.dll" Alias ​​"_Mf500PiccRead @ 8" (ByVal addr As UShort, ByRef value as Long) Like Int or use Integer

Public function PiccRead (ByVal addr As UShort, ByRef value as Long) As Int or Integer Return RFID_PiccRead (addr, value) Final function

0
source

Source: https://habr.com/ru/post/1734395/


All Articles