问题
I am relative new in c# and I want to use this uDMX API, but when I try to add the uDMX.dll file I get this error: "The reference is not vaild or not supported" (see screenshot (in german)) - I can't add images yet -
Or am I doing it completely wrong? I did not find another uDMX api or .dll file.
Hope for your help and Ideas.
回答1:
You cant import an unmanaged win32 dll into a managed c# application like that, you need to specify the methods and parameters yourself.
The uDMX api exposes these methods
bool _stdcall Configure() ;
bool _stdcall Connected() ;
bool _stdcall ChannelSet(long Channel, long Value) ;
bool _stdcall ChannelsSet(long ChannelCnt, long Channel, long* Value) ;
bool _stdcall Info() ;
In order to use them in managed code, you need to provide the declaration, return value and parameters to .Net
This is done by marking a method as external and informing .Net where to find it, use the DllImport
attribute found in the System.Runtime.InteropServices
namespace.
using System;
using System.Runtime.InteropServices;
class uDMXTest
{
[DllImport("uDMX.dll")]
public static extern bool Configure();
public static void Main()
{
bool result;
result = Configure();
Console.WriteLine(result);
}
}
Example on howto provide a declaration of the Configure method, and howto use it. You can declare the other methods in uDMX.dll the same way - note you may need to give the full path to uDMX.dll in the DllImport attribute
More info here : https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute?view=netframework-4.8
来源:https://stackoverflow.com/questions/59311959/using-udmx-api-in-c-sharp