I have a similar question to @m_yasinhan, with a slight differences.
The function that I want to call from C is:
usb_dev_handle* __stdcall xxusb_device_open(struct usb_device *dev);
Where usb_device
is defined as:
struct usb_device {
struct usb_device *next, *prev;
char filename[LIBUSB_PATH_MAX];
struct usb_bus *bus;
struct usb_device_descriptor descriptor;
struct usb_config_descriptor *config;
void *dev; /* Darwin support */
unsigned char devnum;
unsigned char num_children;
struct usb_device **children;
};
In Julia, I defined two structs as:
mutable struct UDH end
mutable struct UD end
ud = UD()
Then, I call the c funtion as:
ccall((:xxusb_device_open, "libxxusb.dll"), Ref{UDH}, (Ref{UD},), ud)
#Also tried this
#ccall((:xxusb_device_open, "libxxusb.dll"), Ptr{UDH}, (Ptr{UD},), ud)
This way has always worked with me except for this function/struct where I get the following error:
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x5b503d85 -- usb_set_configuration at C:\WINDOWS\SYSTEM32\libusb0.dll (unknown line)
in expression starting at REPL[5]:1
usb_set_configuration at C:\WINDOWS\SYSTEM32\libusb0.dll (unknown line)
xxusb_device_open at C:\WINDOWS\SYSTEM32\libxxusb.dll (unknown line)
top-level scope at .\REPL[5]:1
jl_fptr_args at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2016
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2247 [inlined]
jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2254
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win32/build/src\toplevel.c:876
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win32/build/src\toplevel.c:830
jl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win32/build/src\toplevel.c:894 [inlined]
jl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win32/build/src\toplevel.c:944
eval at .\boot.jl:373 [inlined]
eval_user_input at C:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.7\REPL\src\REPL.jl:150
repl_backend_loop at C:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.7\REPL\src\REPL.jl:246
start_repl_backend at C:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.7\REPL\src\REPL.jl:231
#run_repl#47 at C:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.7\REPL\src\REPL.jl:364
run_repl at C:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.7\REPL\src\REPL.jl:351
jl_fptr_args at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2016
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2228 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2429
#936 at .\client.jl:394
_jfptr_YY.936_32814.clone_1 at C:\Users\alqasem.2\AppData\Local\Programs\Julia-1.7.3\lib\julia\sys.dll (unknown line)
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2228 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2429
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1788 [inlined]
jl_f__call_latest at /cygdrive/c/buildbot/worker/package_win32/build/src\builtins.c:757
#invokelatest#2 at .\essentials.jl:716 [inlined]
invokelatest at .\essentials.jl:714 [inlined]
run_main_repl at .\client.jl:379
exec_options at .\client.jl:309
_start at .\client.jl:495
_jfptr__start_34933.clone_1 at C:\Users\alqasem.2\AppData\Local\Programs\Julia-1.7.3\lib\julia\sys.dll (unknown line)
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2228 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2429
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1788 [inlined]
true_main at /cygdrive/c/buildbot/worker/package_win32/build/src\jlapi.c:559
jl_repl_entrypoint at /cygdrive/c/buildbot/worker/package_win32/build/src\jlapi.c:701
jl_load_repl at /cygdrive/c/buildbot/worker/package_win32/build/cli\loader_lib.c:220
mainCRTStartup at /cygdrive/c/buildbot/worker/package_win32/build/cli\loader_exe.c:42
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlGetAppContainerNamedObjectPath at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
RtlGetAppContainerNamedObjectPath at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 2722 (Pool: 2717; Big: 5); GC: 0
Does anyone know why this cannot work, and how to fix it?
Thank you