Skip to main content
Visitor II
December 14, 2021
Solved

How to use DLL CR95HF.dll on VB.NET?

  • December 14, 2021
  • 11 replies
  • 3863 views

Hi eveyone,

I need to use the CR95HF.dll library on a VB.NET application but when i try insert on the project i get an error.

I think this library is VB compatible only but i dont sure about this.

Maybe anyone know how to port this library to be used on VB.NET or how could i use on NET platform.

Thanks.

Regards,

    This topic has been closed for replies.
    Best answer by NFC/RFID Customer support

    Hi,

    another suggestion :

    Using Visual Studio 2015, the format of DLL answer need to be formatted before to be used :

    1. Dim strAnswer = New String(CChar(""), 256)

    You must use this formatted variable in all functions to get DLL answer .

    another suggestion : it is possible that Get DLL revision doesn't return "0" when you get DLL revision number.

    You can can see the exact value with debug mode.

    Hope this will help you,

    Best regards,

    NFC Customer support

    11 replies

    Technical Moderator
    December 14, 2021

    Hi,

    you will find the documentation of the DLL in AN3954. Can you describe the error you have ?

    Rgds

    BT

    DosanAuthor
    Visitor II
    December 14, 2021

    I am curently using VB.Net 2019 and i need to know how can i add the dll correctly.

    If i use the solution of this topic: https://community.st.com/s/question/0D53W000006Oq6qSAC/error-while-loading-cr95hfdll-file

    I get an error "System.BadImageFormatException:"

    I dont know if this library is compatible with vb.net 2019 version.

    Any sugestion?

    Thanks.

    Regards,

    Technical Moderator
    December 14, 2021

    Hi,

    the DLL has been tested with an older version of VB.Net so I have no status with version 2019. The following module declaration has been used:

    Module mod_CR95HFdll
     
     
     
     
    Public Declare Function CR95HFDll_Echo Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_essai Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_Idn Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_Select Lib "CR95HF.dll" (ByVal mycmdstring As String, ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_SendReceive Lib "CR95HF.dll" (ByVal mycmdstring As String, ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_STCmd Lib "CR95HF.dll" (ByVal mycmdstring As String, ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_FieldOff Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_GetDLLrev Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_ResetSPI Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_SendIRQPulse Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDLL_getMCUrev Lib "CR95HF.dll" (ByVal mystring As String) As Long
    'from DLL revision 0.4
    Public Declare Function CR95HFDLL_getInterfacePinState Lib "CR95HF.dll" (ByVal mystring As String) As Long
    'from DLL revision 0.5
    Public Declare Function CR95HFDLL_USBconnect Lib "CR95HF.dll" () As Long
    Public Declare Function CR95HFDll_Polling_Reading Lib "CR95HF.dll" (ByVal mystring As String) As Long
    Public Declare Function CR95HFDll_SendNSSPulse Lib "CR95HF.dll" (ByVal mystring As String) As Long
    'from DLL revision 0.6
    Public Declare Function CR95HFDLL_USBhandlecheck Lib "CR95HF.dll" () As Long
    'from DLL revision 0.9
    Public Declare Function CR95HFDLL_getHardwareVersion Lib "CR95HF.dll" (ByVal mystring As String) As Long
     
     
     
    End Module

    I've seen a lot a posts about System.BadImageFormatException in various forums with many different solutions (32 bits version 64bits, version, path, etc.). Not an easy issue to solve.

    Rgds

    BT

    P.-S. : updated status: tested ok with Visual Studio 15 VB.NET

    DosanAuthor
    Visitor II
    December 15, 2021

    Hi,

    I could solve this problem setting the compilador to x86 (32 bits), but the library dont works well. Some functions respond but other not.

    Functions as USB connect, Handlecheck work aparently well.

    For example:

     Public Declare Function CR95HFDll_GetDLLrev Lib "CR95HF.dll" (ByVal mystring As String) As Long 
     
     Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
     
     Dim strAnswer As String = 0
     Dim lngStatus As Long
     
     lngStatus = CR95HFDll_GetDLLrev(strAnswer)
     
     If (lngStatus = 0) Then
     TextBox1.Text = strAnswer
     Else
     TextBox1.Text = "Error = no Dll found"
     End If
     
     TextBox2.Text = lngStatus
     
     End Sub

    In this case always get dll not found and the library dll was copied to system32 folder.

    and other funtion that try to comunicate with STM or CH95RF work wrong or brake the code execution.

    Maybe my code is not correct but i am using the code examples from: fan3954-developing-your-own-visual-basic-or-cc-application-on-a-cr95hf-demonstration-board-stmicroelectronics

    Thnaks.

    Regards,

    Technical Moderator
    December 15, 2021

    Hi,

    if USB connect or Handlecheck API are running fine, this means that the application can properly load the DLL. So this sounds strange that CR95HFDll_GetDLLrev returns an error except if the CR95HF.dll is an old one. Make sure to use the DLL from the latest STSW-95HF001 package. The date of modification of the DLL is 1/23/2017 4.58PM.

    Rgds

    BT

    DosanAuthor
    Visitor II
    December 16, 2021

    I have tried this but dont works. Same issues.

    Maybe i need to work with Visual Studio 2015

    Thanks.

    Regards,

    DosanAuthor
    Visitor II
    December 16, 2021

    The functions that need return info dont work. So, could be a bad code programming.

    The examples on documents dont work on Visual Basic .NET 2019 and i have tried with 2015 and the problem is the same.

    Regards,

    ST Employee
    December 16, 2021

    Hi,

    another suggestion :

    Using Visual Studio 2015, the format of DLL answer need to be formatted before to be used :

    1. Dim strAnswer = New String(CChar(""), 256)

    You must use this formatted variable in all functions to get DLL answer .

    another suggestion : it is possible that Get DLL revision doesn't return "0" when you get DLL revision number.

    You can can see the exact value with debug mode.

    Hope this will help you,

    Best regards,

    NFC Customer support

    DosanAuthor
    Visitor II
    December 16, 2021

    That´s the solution. A correct format of variable declaration and Public declaration

    Public Declare Function CR95HFDll_GetDLLrev Lib "CR95HF.dll" (ByVal mystring As String) As System.UInt32

    Ok, thaks.

    Problem solved

    DosanAuthor
    Visitor II
    March 30, 2022

    I have a new question about the library and VB.Net IDE programming platform. I can´t open new post so add my question here because could be related.

    I want to know if there is any option to use more than one demo reader conneted to the same PC.

    The library could have some function to select a specific USB iSerielNumber? or how could use the CR95HF library to connect a specific reader?

    Im using VB.Net 2019.

    Thanks,

    Regards.

    ST Employee
    March 30, 2022

    Hi,

    there is no possibility to use several CR95HF readers at the same time with one computer.

    this is due to the DLL used to communicate with the reader. No functionality is provided to manage multiple readers inside the DLL.

    Best regards,

    NFC Customer support

    DosanAuthor
    Visitor II
    March 31, 2022

    Thanks for your response.

    Could be possible get the library Sorce Code ?

    Regards,

    ST Employee
    April 1, 2022

    Hi,

    the CR95HF DLL project is for demonstration purpose and the source code of this DLL is not designed for being used as reference code. This is the reason why we don't deliver it on our internet web site. Anyway if you want to use it to develop our own platform, you have to know that this project is not certified by ST, no documentation exist and the support is very limited.

    Best regards,

    NFC Customer support