dyxnie
dyxnie
CC#
Created by dyxnie on 5/13/2024 in #help
not properly import dll in c# godot
Error:
E 0:00:00:0962 nint HIDapi.hid_enumerate(ushort, ushort): System.DllNotFoundException: Unable to load DLL 'hidapi' or one of its dependencies: The specified module could not be found. (0x8007007E)
<C++ Error> System.DllNotFoundException
<C++ Source> :0 @ nint HIDapi.hid_enumerate(ushort, ushort)
<Stack Trace> :0 @ nint HIDapi.hid_enumerate(ushort, ushort)
WiimoteManager.cs:67 @ bool WiimoteApi.WiimoteManager._FindWiimotes(WiimoteApi.WiimoteType)
WiimoteManager.cs:41 @ bool WiimoteApi.WiimoteManager.FindWiimotes()
WiimoteConnection.cs:42 @ void WiimoteConnection.FindWiimotes()
WiimoteTest.cs:15 @ void WiimoteTest._Ready()
Node.cs:2137 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
WiimoteTest_ScriptMethods.generated.cs:48 @ bool WiimoteTest.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)
E 0:00:00:0962 nint HIDapi.hid_enumerate(ushort, ushort): System.DllNotFoundException: Unable to load DLL 'hidapi' or one of its dependencies: The specified module could not be found. (0x8007007E)
<C++ Error> System.DllNotFoundException
<C++ Source> :0 @ nint HIDapi.hid_enumerate(ushort, ushort)
<Stack Trace> :0 @ nint HIDapi.hid_enumerate(ushort, ushort)
WiimoteManager.cs:67 @ bool WiimoteApi.WiimoteManager._FindWiimotes(WiimoteApi.WiimoteType)
WiimoteManager.cs:41 @ bool WiimoteApi.WiimoteManager.FindWiimotes()
WiimoteConnection.cs:42 @ void WiimoteConnection.FindWiimotes()
WiimoteTest.cs:15 @ void WiimoteTest._Ready()
Node.cs:2137 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
WiimoteTest_ScriptMethods.generated.cs:48 @ bool WiimoteTest.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)
2 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
tried recompiling the dll with the c and h file im pretty sure were used: hidapi.c: https://pastebin.com/FnPPsZM8 hidapi.h: https://pastebin.com/JK74uLyc Command i used for compiling: gcc -shared -o hidapi.dll hidapi.c -lsetupapi How i reference it in my csproj:
<ItemGroup>
<Reference Include="hidapi.dll"/>
</ItemGroup>
<ItemGroup>
<Reference Include="hidapi.dll"/>
</ItemGroup>
My HIDapi.cs (Wrapper): https://pastebin.com/V3pRPDhk
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
does the import look right to you?
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
i guess so if all the other things are being compiled
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
the hidapi wrapper (i believe it is called like that) was copied over from the unity extension
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
i have never really programmed in c# outside of some unity related stuff so ill look into it
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
No description
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
...
[DllImport("hidapi")]
public static extern int hid_read_timeout(IntPtr dev, byte[] data, UIntPtr length, int milliseconds);

[DllImport("hidapi")]
public static extern int hid_send_feature_report(IntPtr device, byte[] data, UIntPtr length);

[DllImport("hidapi")]
public static extern int hid_set_nonblocking(IntPtr device, int nonblock);

[DllImport("hidapi")]
public static extern int hid_write(IntPtr device, byte[] data, UIntPtr length);
}

struct hid_device_info {
public string path;
public ushort vendor_id;
public ushort product_id;
public string serial_number;
public ushort release_number;
public string manufacturer_string;
public string product_string;
public ushort usage_page;
public ushort usage;
public int interface_number;
public IntPtr next;
}
...
[DllImport("hidapi")]
public static extern int hid_read_timeout(IntPtr dev, byte[] data, UIntPtr length, int milliseconds);

[DllImport("hidapi")]
public static extern int hid_send_feature_report(IntPtr device, byte[] data, UIntPtr length);

[DllImport("hidapi")]
public static extern int hid_set_nonblocking(IntPtr device, int nonblock);

[DllImport("hidapi")]
public static extern int hid_write(IntPtr device, byte[] data, UIntPtr length);
}

struct hid_device_info {
public string path;
public ushort vendor_id;
public ushort product_id;
public string serial_number;
public ushort release_number;
public string manufacturer_string;
public string product_string;
public ushort usage_page;
public ushort usage;
public int interface_number;
public IntPtr next;
}
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
using System.Runtime.InteropServices;
using System.Collections;
using System;
using System.Text;

public class HIDapi {

[DllImport("hidapi")]
public static extern int hid_init();

[DllImport("hidapi")]
public static extern int hid_exit();

[DllImport("hidapi")]
public static extern IntPtr hid_error(IntPtr device);

[DllImport("hidapi")]
public static extern IntPtr hid_enumerate(ushort vendor_id, ushort product_id);

[DllImport("hidapi")]
public static extern void hid_free_enumeration(IntPtr devs);

[DllImport("hidapi")]
public static extern int hid_get_feature_report(IntPtr device, byte[] data, UIntPtr length);

[DllImport("hidapi")]
public static extern int hid_get_indexed_string(IntPtr device, int string_index, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern int hid_get_manufacturer_string(IntPtr device, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern int hid_get_product_string(IntPtr device, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern int hid_get_serial_number_string(IntPtr device, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern IntPtr hid_open(ushort vendor_id, ushort product_id, string serial_number);

[DllImport("hidapi")]
public static extern void hid_close(IntPtr device);

[DllImport("hidapi")]
public static extern IntPtr hid_open_path(string path);

[DllImport("hidapi")]
public static extern int hid_read(IntPtr device, byte[] data, UIntPtr length);

...
using System.Runtime.InteropServices;
using System.Collections;
using System;
using System.Text;

public class HIDapi {

[DllImport("hidapi")]
public static extern int hid_init();

[DllImport("hidapi")]
public static extern int hid_exit();

[DllImport("hidapi")]
public static extern IntPtr hid_error(IntPtr device);

[DllImport("hidapi")]
public static extern IntPtr hid_enumerate(ushort vendor_id, ushort product_id);

[DllImport("hidapi")]
public static extern void hid_free_enumeration(IntPtr devs);

[DllImport("hidapi")]
public static extern int hid_get_feature_report(IntPtr device, byte[] data, UIntPtr length);

[DllImport("hidapi")]
public static extern int hid_get_indexed_string(IntPtr device, int string_index, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern int hid_get_manufacturer_string(IntPtr device, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern int hid_get_product_string(IntPtr device, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern int hid_get_serial_number_string(IntPtr device, StringBuilder str, UIntPtr maxlen);

[DllImport("hidapi")]
public static extern IntPtr hid_open(ushort vendor_id, ushort product_id, string serial_number);

[DllImport("hidapi")]
public static extern void hid_close(IntPtr device);

[DllImport("hidapi")]
public static extern IntPtr hid_open_path(string path);

[DllImport("hidapi")]
public static extern int hid_read(IntPtr device, byte[] data, UIntPtr length);

...
(text too long)
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
And this is my wrapped HIDapi.cs:
16 replies
CC#
Created by dyxnie on 5/12/2024 in #help
Properly import dll in csproj
And this is my .csproj:
<Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>surfsSportResort</RootNamespace>
</PropertyGroup>

<ItemGroup>
<!-- Reference to hidapi.dll for win64 platform -->
<PrivateReference Include="hidapi">
<HintPath>$(MSBuildThisFileDirectory)Wiimote Godot API\Plugins\win32\hidapi.dll</HintPath>
</PrivateReference>
</ItemGroup>

<ItemGroup Condition="'$(Platform)'=='x64'">
<!-- Reference to hidapi.dll for win32 platform -->
<PrivateReference Include="hidapi">
<HintPath>$(MSBuildThisFileDirectory)Wiimote Godot API\Plugins\win64\hidapi.dll</HintPath>
</PrivateReference>
</ItemGroup>
</Project>
<Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>surfsSportResort</RootNamespace>
</PropertyGroup>

<ItemGroup>
<!-- Reference to hidapi.dll for win64 platform -->
<PrivateReference Include="hidapi">
<HintPath>$(MSBuildThisFileDirectory)Wiimote Godot API\Plugins\win32\hidapi.dll</HintPath>
</PrivateReference>
</ItemGroup>

<ItemGroup Condition="'$(Platform)'=='x64'">
<!-- Reference to hidapi.dll for win32 platform -->
<PrivateReference Include="hidapi">
<HintPath>$(MSBuildThisFileDirectory)Wiimote Godot API\Plugins\win64\hidapi.dll</HintPath>
</PrivateReference>
</ItemGroup>
</Project>
I tried importing it with the help of AI but it didnt really work..
16 replies