melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices
https://melanchall.github.io/drywetmidi
MIT License
540 stars 75 forks source link

PInvokeStackImbalance exception on native calls in 32-bit app #142

Closed toby11 closed 2 years ago

toby11 commented 2 years ago

In in a windows .net forms app on calling

var allDevices = InputDevice.GetAll()

I get this exception? Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'Melanchall.DryWetMidi!Melanchall.DryWetMidi.Multimedia.MidiDevicesSessionApi32::OpenSession_Win' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

toby11 commented 2 years ago

Windows 10 and .net 4.7.2 - vs2021, tried building it with x86 and AnyCPU but still the same error.

melanchall commented 2 years ago

Thanks for the issue. Can you please say is your Windows 32 or 64 bit?

toby11 commented 2 years ago

@melanchall thanks for the quick reply its 64bit

Processor Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz 3.30 GHz Installed RAM 32.0 GB System type 64-bit operating system, x64-based processor Pen and touch Pen and touch support with 10 touch points

Edition Windows 10 Enterprise Version 21H1 Installed on ‎22/‎10/‎2020 OS build 19043.1415 Experience Windows Feature Experience Pack 120.2212.3920.0

toby11 commented 2 years ago

in fact just changed my project to compile in x64 and it now works with no errors

however on using InputDevice.GetAll()

I get "Enumeration yielded no results" whereas I have multiple midi input devices.

toby11 commented 2 years ago

Actually I was connected to my dev machine via rdp so think that's why it was returning no input devices.

So the issue was resolved by just compiling as x64 in visual studio. Thanks

melanchall commented 2 years ago

I'm reopening the issue. I'm able to reproduce the error in a fresh WinForms app running in 32-bit process. The library is supposed to work in 32-bit Windows apps too, so I'll try to fix the issue.

melanchall commented 2 years ago

The problem is solved now. You can install prerelease version of the library NuGet package – 6.1.0-prerelease1.

melanchall commented 2 years ago

:rocket: 6.1.0 version is released now!

Prerelease NuGet packages will be unlisted soon, so please update the package references to the new version.

Thanks for using the library!