hi, i made a vb.net project thant make connection between PC and PIC18F2550 using usb temple (USB HID) when i run it i have this message "badimage exception". I use windows 7 64 bits .
please help me
this is the code.

Welcome to DaniWeb. It's ok to put your code directly into your post. Use the Code option in the edit window menu.

In addition to the code we also need the exact wording of the whole exception and the line in the code that triggered the exception.

Public Class Form1
    ' vendor and product IDs
    Private Const VendorID As Integer = &H1234    'Replace with your device's
    Private Const ProductID As Integer = &H1      'product and vendor IDs

    ' read and write buffers
    Private Const BufferInSize As Integer = 64 'Size of the data buffer coming IN to the PC
    Private Const BufferOutSize As Integer = 65    'Size of the data buffer going OUT from the PC
    Dim BufferIn(BufferInSize) As Byte          'Received data will be stored here - the first byte in the array is unused
    Dim BufferOut(BufferOutSize) As Byte    'Transmitted data is stored here - the first item in the array must be 0

    Public Function AsciiByteToChar(ByVal b As Byte) As Char

        Dim barr() As Byte = New Byte() {b}

        Dim carr() As Char = Encoding.ASCII.GetChars(barr)

        Return carr(0)

    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ConnectToHID(Me)
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        DisconnectFromHID()
    End Sub

    ' a HID device has been plugged in...********
    Public Sub OnPlugged(ByVal pHandle As Integer)
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
            MsgBox("Device connected", vbOKOnly, "USB")
        End If
    End Sub

    '*****************************************************************
    ' a HID device has been unplugged...
    '*****************************************************************
    Public Sub OnUnplugged(ByVal pHandle As Integer)
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
            hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
            MsgBox("Device unplugged", vbOKOnly, "USB")
        End If
    End Sub

BadImageException

In addition to the code we also need the exact wording of the whole exception and the line in the code that triggered the exception.

Error:" Une exception de première chance de type 'System.BadImageFormatException' s'est produite dans USBTemplate21.exe" without line

Also (Exception de HRESULT : 0x8007000B)

@ tinstaafl, please i need your help when i connect the microcontroller to usb port i listent the sound of connection but the vb.net interface does not work. can you help me

The exception seems to be because the library you're using is incompatible with the visual studio you're using. You'll have to check the source of the library and see if there is a better version for you.

Here's the documentation on using usb devices with .net

Hello tinstaafl, thanks i well try it and i will tell u the result .

@ tinsttafl i cant find any solution in that links , what about vb.net 2008? i can try whith it or i have a mistake in the syntaxe?!!

no way, thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.