[Mono-list] hiddev in C#

Jonathan Pryor jonpryor at vt.edu
Sat Nov 10 16:51:31 EST 2007


On Sat, 2007-11-10 at 11:34 -0800, ghell wrote:
> I want to use hiddev from C# (or anything else that will allow me to use HID
> in C# on linux if there is something else). However, hiddev.h contains
> mostly macros and a couple of structs.
> 
> Which file can I DllImport to use hiddev and how would I go about converting
> this C into C#?
> 
> struct hiddev_devinfo device_info;
> ioctl(fd, HIDIOCGDEVINFO, &device_info);

Something like this (untested):

        struct HiddevDevinfo {
            uint bustype;
            uint busnum;
            uint devnum;
            uint ifnum;
            short vendor;
            short product;
            short version;
            uint num_applications;
        }
        
        class YourClass {
            const int HIDIOCGDEVINFO = 
                2 << 30 |
                ((int) 'H') << 8 |
                0x03 << 0 |
                sizeof(HiddevDevinfo) << 16
        
            [DllImport ("libc.so")]
            private static extern int ioctl (int filedes, int request,
                ref HiddevDevInfo info);
        }

As for the HIDIOCGDEVINFO value, the _IOR() macro is in
asm-generic/ioctl.h, so you can piece together things manually or use a
test program.

 - Jon




More information about the Mono-list mailing list