Hello,
You can use free online convesion tools.
For example
http://www.developerfusion.com/tools/convert/vb-to-csharp/[
^]
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
static class HIDDLLInterface
{
[DllImport("mcHID.dll", EntryPoint = "Connect", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidConnect(int pHostWin);
[DllImport("mcHID.dll", EntryPoint = "Disconnect", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidDisconnect();
[DllImport("mcHID.dll", EntryPoint = "GetItem", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetItem(int pIndex);
[DllImport("mcHID.dll", EntryPoint = "GetItemCount", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetItemCount();
[DllImport("mcHID.dll", EntryPoint = "Read", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidRead(int pHandle, ref byte pData);
[DllImport("mcHID.dll", EntryPoint = "Write", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidWrite(int pHandle, ref byte pData);
[DllImport("mcHID.dll", EntryPoint = "ReadEx", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidReadEx(int pVendorID, int pProductID, ref byte pData);
[DllImport("mcHID.dll", EntryPoint = "WriteEx", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidWriteEx(int pVendorID, int pProductID, ref byte pData);
[DllImport("mcHID.dll", EntryPoint = "GetHandle", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetHandle(int pVendoID, int pProductID);
[DllImport("mcHID.dll", EntryPoint = "GetVendorID", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetVendorID(int pHandle);
[DllImport("mcHID.dll", EntryPoint = "GetProductID", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetProductID(int pHandle);
[DllImport("mcHID.dll", EntryPoint = "GetVersion", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetVersion(int pHandle);
[DllImport("mcHID.dll", EntryPoint = "GetVendorName", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetVendorName(int pHandle, string pText, int pLen);
[DllImport("mcHID.dll", EntryPoint = "GetProductName", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetProductName(int pHandle, string pText, int pLen);
[DllImport("mcHID.dll", EntryPoint = "GetSerialNumber", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetSerialNumber(int pHandle, string pText, int pLen);
[DllImport("mcHID.dll", EntryPoint = "GetInputReportLength", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetInputReportLength(int pHandle);
[DllImport("mcHID.dll", EntryPoint = "GetOutputReportLength", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int hidGetOutputReportLength(int pHandle);
[DllImport("mcHID.dll", EntryPoint = "SetReadNotify", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern void hidSetReadNotify(int pHandle, bool pValue);
[DllImport("mcHID.dll", EntryPoint = "IsReadNotifyEnabled", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidIsReadNotifyEnabled(int pHandle);
[DllImport("mcHID.dll", EntryPoint = "IsAvailable", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool hidIsAvailable(int pVendorID, int pProductID);
[DllImport("user32", EntryPoint = "CallWindowProcA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int CallWindowProc(int lpPrevWndFunc, int hwnd, int Msg, int wParam, int lParam);
[DllImport("user32", EntryPoint = "SetWindowLongA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SetWindowLong(int hwnd, int nIndex, int dwNewLong);
public delegate int SubClassProcDelegate(int hwnd, int msg, int wParam, int lParam);
[DllImport("USER32.DLL", EntryPoint = "SetWindowLongA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int DelegateSetWindowLong(int hwnd, int attr, SubClassProcDelegate lval);
public const int WM_APP = 32768;
public const short GWL_WNDPROC = -4;
private const decimal WM_HID_EVENT = WM_APP + 200;
private const short NOTIFY_PLUGGED = 1;
private const short NOTIFY_UNPLUGGED = 2;
private const short NOTIFY_CHANGED = 3;
private const short NOTIFY_READ = 4;
private static int FPrevWinProc;
private static int FWinHandle;
private static SubClassProcDelegate Ref_WinProc = new SubClassProcDelegate(WinProc);
private static object HostForm;
public static bool ConnectToHID(ref Form targetForm)
{
int pHostWin = targetForm.Handle.ToInt32;
FWinHandle = pHostWin;
pHostWin = hidConnect(FWinHandle);
FPrevWinProc = DelegateSetWindowLong(FWinHandle, GWL_WNDPROC, Ref_WinProc);
HostForm = targetForm;
}
public static bool DisconnectFromHID()
{
bool functionReturnValue = false;
functionReturnValue = hidDisconnect();
SetWindowLong(FWinHandle, GWL_WNDPROC, FPrevWinProc);
return functionReturnValue;
}
private static int WinProc(int pHWnd, int pMsg, int wParam, int lParam)
{
if (pMsg == WM_HID_EVENT) {
switch (wParam) {
case
NOTIFY_PLUGGED:
HostForm.OnPlugged(lParam);
break;
case
NOTIFY_UNPLUGGED:
HostForm.OnUnplugged(lParam);
break;
case
NOTIFY_CHANGED:
HostForm.OnChanged();
break;
case
NOTIFY_READ:
HostForm.OnRead(lParam);
break;
}
}
return CallWindowProc(FPrevWinProc, pHWnd, pMsg, wParam, lParam);
}
}
All you will need to do is to correct the generated code and make it work.
Valery.