Dll exception

kaveh rahimi 66 Reputation points
2021-06-07T09:33:58.867+00:00

The code below is a part of my form2 code.When I debug it I receive an exception depending on ch341dll.dll file:
Private Declare Function ch341opendevice Lib "ch341dll.dll" (ByVal iindex As Integer) As Integer
Sub main()
MsgBox("ok")
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim opening As Integer
    opening = ch341opendevice(0)
    Console.WriteLine(opening)
End Sub
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,819 questions
{count} votes

Accepted answer
  1. RLWA32 47,956 Reputation points
    2021-06-09T09:34:58.967+00:00

    The exported name is "CH341OpenDevice" but the posted code Declare statement uses "ch341opendevice". Use the exact name exported from the dll. Also, when you run Dll Export Viewer make sure that the startup option "Undecorate C++ names" is unchecked.


2 additional answers

Sort by: Most helpful
  1. RLWA32 47,956 Reputation points
    2021-06-07T12:44:49.293+00:00

    It is likely that the function is exported by a different name from the DLL.

    In a VS Command Prompt window run - dumpbin /exports ch341dll.dll

    This will show you the names of the functions exported from the DLL.


  2. kaveh rahimi 66 Reputation points
    2021-06-08T11:14:22.093+00:00

    I did that but the result was an error,and dumpbin is not recognized.Which command line I have to write exactly?What are sequences of this work?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.