I'm trying to use libusb-win32 (http://libusb-win32.sourceforge.net/)
via #libusb (http://www.icsharpcode.net/opensource/sharpusblib/) with
.NET 2.0 on Windows XP SP2. I keep getting an exception from a
function, usb_get_busses(). It works the first time I call it, but
throws an exception if I call it after usb_get_busses():
Got Exception (Form1->parseBusses): System.AccessViolationException:
Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.
at USBlib.Internal.NativeMethods.usb_find_busses()
USBlib.Internal.NativeMethods contains the interop wrappers around the c
functions (code from #libusb):
[DllImport("libusb0.dll", CallingConvention = CallingConvention.Cdecl,
ExactSpelling = true), SuppressUnmanagedCodeSecurity]
public static extern int usb_find_busses();
[DllImport("libusb0.dll", CallingConvention = CallingConvention.Cdecl,
ExactSpelling = true), SuppressUnmanagedCodeSecurity]
public static extern usb_bus usb_get_busses();
The c function, usb_find_busses updates a global pointer, *usb_busses,
within the c code, and usb_get_busses() returns it (code from libusb-win32):
//usb.c
struct usb_bus *usb_busses = NULL;
int usb_find_busses(void)
{
// updates the usb_busses pointer to point to a linked list of busses
}
struct usb_bus *usb_get_busses(void) //returns the global pointer
Why is this crashing? How do I fix it? There should be no problm
calling usb_get_busses() as many times as desired. Is this the wrong
way to deal with a return value of a pointer to a struct?
T
Thomas Spellman - 19 Mar 2006 22:12 GMT
I'm getting so many different problems from this code. Sometimes it
just works, and if it works, it keeps working. BUT, sometimes I get an
AccessViolationException (reading or writing protected memory),
sometimes i get a stack overrun, sometimes it just quits, sometimes it
freezes. Sometimes the exception popup points to the interop function,
sometimes it points to the dispose function, sometimes to the
Application.Run function. How should I debug this interop stuff? How
do I know what code in the DLL is the problem? I have the code for it.
Is it possible to bedug both the CLR and the native code? I only have
C# Express, do I need the Pro edition for this? I have VS2003 Pro,
would that be better for debugging this interop stuff?
T
> I'm trying to use libusb-win32 (http://libusb-win32.sourceforge.net/)
> via #libusb (http://www.icsharpcode.net/opensource/sharpusblib/) with
[quoted text clipped - 37 lines]
>
> T