Hi all, I'm controlling my self-designed USB device using SCSI interface with C by opening a file handle, ioctl and using sg_io_hdr_t structure. I have to design a GUI, and i should do that with C#. I am not too familiar with C#. Could u suggest a way to do that with C#
A:
You have a few options
1- Use p/invoke (platform invoke) interoperability. Using this you can do one of two things. Either use p/invoke to call the Win32 api from .NET, alternatively you can write a C dll that exports a simplified interface to control the device and then interop to this dll.
2- You could use managed C++, and create a library that you can call from C#.
3- You could wrap your C code as a COM object and use COM interop from C#.
Since you presumably have some working C code, I think the easiest would be to create a DLL that exports a easy to invoke interface and then use P/Invoke to call that from C#
Chris Taylor
2010-06-27 14:38:10
Chris, thanks for your quick answer. My problem is my application shouldn't require any external source . I think this is a problem to use a DLL. I started to use p/invoke method and i opened device with CreateFile. But i'm not sure how can i simulate sg_io_hdr_t structure. Any suggestion?
2010-06-27 15:06:43
@user168574, I have never specifically worked with sg_io_hdr, but the only challenge I see with this struct are the void* dxferp and void* usr_ptr, but I expect that you could handle this by usin an IntPtr and then allocating a buffer big enough for the structure and the additional data for the to void* if required. This is not easy to explain in a comment, but I did a post years ago that did something similar to access the ListViewItem from another process, this might help. http://taylorza.blogspot.com/2010/06/crossing-process-boundary-with-net.html, hope this helps.
Chris Taylor
2010-06-27 15:28:59