現在、G19 に logitech SDK を使用しようとしています。
このトピックに関するすべての情報は 2012 年のものであり、多くのメソッドの名前が変更されたため、新しい .NET ラッパーを作成することにしました。
しかし、私は立ち往生していて、どこにも行きません。
最初にライブラリ プロジェクトを作成しました。ライブラリコードは次のとおりです。
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Logitech_LCD
{
/// <summary>
/// Class containing necessary informations and calls to the Logitech SDK
/// </summary>
public class NativeMethods
{
#region Enumerations
/// <summary>
/// LCD Types
/// </summary>
public enum LcdType
{
Mono = 1,
Color = 2,
}
/// <summary>
/// Screen buttons
/// </summary>
[Flags]
public enum Buttons
{
MonoButton0 = 0x1,
ManoButton1 = 0x2,
MonoButton2 = 0x4,
MonoButton3 = 0x8,
ColorLeft = 0x100,
ColorRight = 0x200,
ColorOK = 0x400,
ColorCancel = 0x800,
ColorUp = 0x1000,
ColorDown = 0x2000,
ColorMenu = 0x4000,
}
#endregion
#region Dll Mapping
[DllImport("LogitechLcd.dll", CallingConvention = CallingConvention.Cdecl))]
public static extern bool LogiLcdInit(String friendlyName, LcdType lcdType);
[DllImport("LogitechLcd.dll", CallingConvention = CallingConvention.Cdecl))]
public static extern bool LogiLcdIsConnected(LcdType lcdType);
#endregion
}
}
次に、ダミーアプリで、次のように呼び出してみましたLogiLcdInit:
Console.WriteLine(Logitech_LCD.NativeMethods.LogiLcdIsConnected(Logitech_LCD.NativeMethods.LcdType.Color));
Console.WriteLine(Logitech_LCD.NativeMethods.LogiLcdInit("test", Logitech_LCD.NativeMethods.LcdType.Color));
Console.WriteLine(Logitech_LCD.NativeMethods.LogiLcdIsConnected(Logitech_LCD.NativeMethods.LcdType.Color));
問題は次のとおりです。これらの行ごとに、PInvokeStackImbalance 例外が発生します。メソッド名以外の詳細はありません。
参照用のLogitech SDKへのリンクは次のとおりです。
編集:回答によるコードの変更を反映するようにコードを変更しました
編集2
これがあなたの答えのおかげで私が作った.NETラッパーです:https://github.com/sidewinder94/Logitech-LCD
ここに置いておくだけで参考になります。