88 *
99 **/
1010
11+ #include <stdbool.h>
1112#include <stdio.h>
1213#include <stdlib.h>
14+ #ifdef _WIN32
15+ #include <windows.h>
16+ #endif
1317
1418#include "CANvenient.h"
1519#include "drivers/CANvenient_internal.h"
1923#include "drivers/CANvenient_Softing.h"
2024#include "drivers/CANvenient_PEAK.h"
2125
26+ #ifdef _WIN32
27+ static HMODULE vciapi_dll_handle = NULL ;
28+ static bool is_vciapi_dll_available = false;
29+ #endif
30+
2231struct can_iface can_interface [CAN_MAX_INTERFACES ] = {0 };
2332char can_error_reason [1024 ] = {0 };
2433
@@ -29,10 +38,37 @@ CANVENIENT_API int can_find_interfaces_mask(u32 vendor_mask)
2938 return 0 ;
3039 }
3140
32- if (vendor_mask & CAN_VENDOR_IXXAT )
41+ #ifdef _WIN32
42+ static bool once_checked_vciapi_dll = false;
43+
44+ // https://github.com/CANopenTerm/CANopenTerm/issues/109#issuecomment-4320171025
45+ if (! once_checked_vciapi_dll )
46+ {
47+ if (GetFileAttributesA ("vciapi.dll" ) != INVALID_FILE_ATTRIBUTES )
48+ {
49+ vciapi_dll_handle = LoadLibraryA ("vciapi.dll" );
50+ if (! vciapi_dll_handle )
51+ {
52+ puts ("vciapi.dll not found. Ixxat interfaces will be ignored." );
53+ is_vciapi_dll_available = false;
54+ }
55+ else
56+ {
57+ is_vciapi_dll_available = true;
58+ }
59+ }
60+ else
61+ {
62+ puts ("vciapi.dll not found. Ixxat interfaces will be ignored." );
63+ }
64+
65+ once_checked_vciapi_dll = true;
66+ }
67+ if (vendor_mask & CAN_VENDOR_IXXAT && is_vciapi_dll_available )
3368 {
3469 ixxat_find_interfaces ();
3570 }
71+
3672 if (vendor_mask & CAN_VENDOR_PEAK )
3773 {
3874 peak_find_interfaces ();
@@ -41,14 +77,17 @@ CANVENIENT_API int can_find_interfaces_mask(u32 vendor_mask)
4177 {
4278 kvaser_find_interfaces ();
4379 }
44- if (vendor_mask & CAN_VENDOR_SOCKETCAN )
45- {
46- socketcan_find_interfaces ();
47- }
80+
4881 if (vendor_mask & CAN_VENDOR_SOFTING )
4982 {
5083 softing_find_interfaces ();
5184 }
85+ #endif
86+
87+ if (vendor_mask & CAN_VENDOR_SOCKETCAN )
88+ {
89+ socketcan_find_interfaces ();
90+ }
5291
5392 return 0 ;
5493}
0 commit comments