I need to build a gui to communicate via bulk USB from my Windows PC to a PIC microcontroller. I'm trying to use mpusbapi.dll as I see over diferent tutorials on internet, but I can´t acommplish to succesfully reference the dll in my project. VS 2015 show me this error: "mpusbapi.dll" could not be added. Make sure that the file is accessible, and that its a valis assembly or COM component.
I did research and i figured out the problem was the unmanaged dll, so I tried to reference via DllImport. But at this time, that did not work either.
I share my code below expecting someone could help me or give me some reference to a better way to accomplish my objective with usb.
using System.Runtime.InteropServices;
namespace GUI_ROBOT
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//Problem here
[DllImport("mpusbapi.dll",CallingConvention = CallingConvention.Cdecl)]
static extern UInt32 MPUSBGetDLLVersion();
[DllImport("mpusbapi.dll")]
static extern UInt32 MPUSBGetDeviceCount(string pVID_PID);
private void btnStart_Click(object sender, RoutedEventArgs e)
{
try
{
string dCount = MPUSBGetDLLVersion().ToString();
listBox1.Items.Add(dCount);
}
catch (Exception j)
{
System.Windows.MessageBox.Show("Error: " + "\nMessage = " +
j.Message);
}
}
}
}
The try catch
statetment give me the follow result:
Error after try catch statetment
Translate "Can´t load the .dll file 'mpuasbapi.dll': Can´t find the specified module."
I don´t undesrtand because I just added the file in my project.
Thanks people!