MIDIHDR 问题

发布于 2024-11-08 11:02:36 字数 731 浏览 9 评论 0原文

我正在尝试在 WinMM.dll 中为 MIDI 函数编写一个包装库,但我在处理 MIDI 长消息时遇到了问题。我在 PIvnoke.net 中找到了这个(我自己添加了第一行):

[StructLayout(LayoutKind.Sequential)]
    public struct MIDIHDR
    {
        IntPtr lpData;
        int dwBufferLength;
        int dwBytesRecorded;
        IntPtr dwUser;
        int dwFlags;
        MIDIHDR lpNext;
        IntPtr reserved;
        int dwOffset;
        IntPtr dwReserved;
    }

但是编译时出现错误:

错误 1 ​​类型为“WinMMM.MidiWrapper.MIDIHDR”的结构成员“WinMMM.MidiWrapper.MIDIHDR.lpNext”导致结构布局中发生循环 C:\Users\Alex\Documents\Visual Studio 2010\Projects\WinMMM\WinMMM \MidiWrapper.cs 219 21 WinMMM

我正在​​使用 Visual Studio Ultimate 2010,我正在制作一个 C# 类库,任何帮助将不胜感激!

I am trying to write a wrapper library for MIDI functions in WinMM.dll, but I am having trouble with MIDI long messages. I found this in PIvnoke.net (I added the first line myself):

[StructLayout(LayoutKind.Sequential)]
    public struct MIDIHDR
    {
        IntPtr lpData;
        int dwBufferLength;
        int dwBytesRecorded;
        IntPtr dwUser;
        int dwFlags;
        MIDIHDR lpNext;
        IntPtr reserved;
        int dwOffset;
        IntPtr dwReserved;
    }

But I get an error while compiling:

Error 1 Struct member 'WinMMM.MidiWrapper.MIDIHDR.lpNext' of type 'WinMMM.MidiWrapper.MIDIHDR' causes a cycle in the struct layout C:\Users\Alex\Documents\Visual Studio 2010\Projects\WinMMM\WinMMM\MidiWrapper.cs 219 21 WinMMM

I am using Visual Studio Ultimate 2010, I am making a C# class library, and any help will be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柳絮泡泡 2024-11-15 11:02:36

您可以将: 更改

MIDIHDR lpNext;

为:

IntPtr lpNext;

来解决您眼前的问题。

MIDL 编译器无法取消引用这些结构链,但如果 API 调用将一个结构作为参数,则通过此更改,到下一个结构的链接将被解码为原始指针,就像第一个字段 lpData 一样代码>.

You can change:

MIDIHDR lpNext;

to:

IntPtr lpNext;

to solve your immediate problem.

The MIDL compiler can't dereference a chain of these structures but if an API call takes one as an argument, with this change the link to the next one will be decoded as a raw pointer, just like first field lpData.

爱,才寂寞 2024-11-15 11:02:36

我不确定你正确的最后一点是否正确。 dwReserved 是一个由四个 DWORD_PTR 组成的数组(请参阅 MIDIHDR MSDN)。你可以使用这样的东西:

    // http://msdn.microsoft.com/en-us/library/dd798449%28VS.85%29.aspx
    [StructLayout(LayoutKind.Sequential)]
    public struct MIDIHDR
    {
        public string lpData;
        public int dwBufferLength;
        public int dwBytesRecorded;
        public IntPtr dwUser;
        public int dwFlags;
        public IntPtr lpNext;
        public IntPtr reserved;
        public int dwOffset;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public IntPtr[] dwReserved;
    }

I'm not sure the final bit of your correct is right. dwReserved is an array of four DWORD_PTRs (see MIDIHDR on MSDN). You could use something like this:

    // http://msdn.microsoft.com/en-us/library/dd798449%28VS.85%29.aspx
    [StructLayout(LayoutKind.Sequential)]
    public struct MIDIHDR
    {
        public string lpData;
        public int dwBufferLength;
        public int dwBytesRecorded;
        public IntPtr dwUser;
        public int dwFlags;
        public IntPtr lpNext;
        public IntPtr reserved;
        public int dwOffset;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public IntPtr[] dwReserved;
    }
梦里寻她 2024-11-15 11:02:36

您还可以将 MIDIHDR 的声明从结构类型更改为类类型。

You could also change the declaration of MIDIHDR from a struct to a class type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文