JNA错误的结果访问设备

时间:2015-03-12 12:58:46

标签: java windows dll jna

我尝试使用JNA访问设备

第一个命令返回一个statusCode 263而不是零。

我搜索并发现此代码,表示“INVALID_DEVICE_NAME”。设备手册说:

  

必须指定MCI_OPEN_TYPE标志,并且lpOpen标识的结构的lpstrDeviceType成员必须包含设备   名称(在我们的例子中是“DictCtrl”)

我的代码中是否有错误?

“相同”代码在编译的delphi应用程序中工作,我的设备被识别。

public class Main {
    public static final int MCI_OPEN = 0x0803;
    public static final int MCI_OPEN_TYPE = 0x00002000;
    public static final int MCI_STATE_STOP = 0x00000001;
    public static final int MCI_OPEN_SHAREABLE = 0x00000100;

public static Winmm winmmLib = Winmm.INSTANCE;

public interface Winmm extends StdCallLibrary {
    Winmm INSTANCE = (Winmm) Native.loadLibrary("winmm", Winmm.class);

    int mciSendCommandA(int IDDevice, int uMsg, int fdwCommand, Structure dwParam);
}

public static class TagmciOpenParmsa extends Structure {

    public int dwCallback;
    public int wDeviceID;
    public String lpstrDeviceType;
    public String lpstrElementName;
    public String lpstrAlias;

    @Override
    protected List getFieldOrder() {
        return Arrays.asList(new String[] { "dwCallback", "wDeviceID", "lpstrDeviceType", "lpstrElementName", "lpstrAlias" });
    }
}

public static void main(String[] args) {
    TagmciOpenParmsa tagmciOpenParmsa = new TagmciOpenParmsa();

    tagmciOpenParmsa.lpstrDeviceType = "DictCtrl";


    int ret = winmmLib.mciSendCommandA(0, MCI_OPEN, MCI_OPEN_TYPE, tagmciOpenParmsa); // | MixerConstants.MCI_OPEN_SHAREABLE
    System.out.println(ret);
}

}

0 个答案:

没有答案