Hi,
I'm new to rust and am just trying to call a windows midi function - I found a nice intro to this at lowmidi.htm
So my code compiles and runs, but I get no names coming back in the structure, while others (in other languages) do here (search cos cannot post links) - how-to-get-midi-device-names
The output of running my code is below, I was hoping that the AAA would be set by the windows function to the names of my midi devices. It correctly notices my midi device when I turn it on/off in the count, but the names do not appear.
Any ideas? Am I making an obvious rookie error? I'm on Windows 10 Home 1909, a pretty vanilla dell build.
C:/Users/dave/.cargo/bin/cargo.exe run --color=always --package playground_r --bin playground_r
Compiling playground_r v0.1.0 (C:\working\rust\playground_r)
Finished dev [unoptimized + debuginfo] target(s) in 0.48s
Running `target\debug\playground_r.exe`
Hello, world!
Got num_midi_in of 1
sz is 76
For 0 got ok of 0 and name of Ok("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") all is MIDIINCAPSW { wMid: 0, wPid: 0, vDriverVersion: 0, szPname: [65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65], dwSupport: 0 }
Got num_midi_out of 2
sz is 84
For 0 got ok of 0 and name of Ok("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") all is MIDIOUTCAPSW { wMid: 0, wPid: 0, vDriverVersion: 0, szPname: [65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65], wTechnology: 0, wVoices: 0, wNotes: 0, wChannelMask: 0, dwSupport: 0 }
For 1 got ok of 0 and name of Ok("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") all is MIDIOUTCAPSW { wMid: 0, wPid: 0, vDriverVersion: 0, szPname: [65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65], wTechnology: 0, wVoices: 0, wNotes: 0, wChannelMask: 0, dwSupport: 0 }
Process finished with exit code 0
using cargo.toml of
[package]
name = "playground_r"
version = "0.1.0"
authors = ["dave"]
edition = "2018"
[dependencies]
winmm-sys = "0.2.0"
winapi = "0.2.8"
and code of
#![allow(dead_code)]
#![allow(non_snake_case)]
extern crate winmm;
extern crate winapi;
use std::mem;
use winapi::mmsystem;
mod tests1;
fn main() {
println!("Hello, world!");
check_midi_in();
check_midi_out();
}
fn check_midi_out() {
let num_midi = unsafe {
winmm::midiOutGetNumDevs()
};
println!("Got num_midi_out of {}", num_midi);
let wchar32_space: [u16; 32] = [65; 32];
#[allow(non_snake_case)]
let caps = mmsystem::MIDIOUTCAPSW {
wMid: 0,
wPid: 0,
vDriverVersion: 0,
szPname: wchar32_space,
wTechnology: 0,
wVoices: 0,
wNotes: 0,
wChannelMask: 0,
dwSupport: 0,
};
let raw_caps = Box::into_raw(Box::new(caps));
let sz = mem::size_of::<mmsystem::MIDIOUTCAPSW>();
println!("sz is {}", sz);
for i in 0..num_midi {
let id = i as u64;
let name_ok = unsafe {
winmm::midiOutGetDevCapsW(id, raw_caps, sz as u32)
};
println!("For {} got ok of {} and name of {:?} all is {:?}", id, name_ok, String::from_utf16(&caps.szPname), &caps);
}
}
fn check_midi_in() {
let num_midi_in = unsafe {
winmm::midiInGetNumDevs()
};
println!("Got num_midi_in of {}", num_midi_in);
let wchar32_space: [u16; 32] = [65; 32];
let caps = mmsystem::MIDIINCAPSW {
wMid: 0,
wPid: 0,
vDriverVersion: 0,
szPname: wchar32_space,
dwSupport: 0
};
let raw_caps = Box::into_raw(Box::new(caps));
let sz = mem::size_of::<mmsystem::MIDIINCAPSW>();
println!("sz is {}", sz);
for i in 0..num_midi_in {
let id = i as u64;
let name_ok = unsafe {
winmm::midiInGetDevCapsW(id, raw_caps, sz as u32)
};
println!("For {} got ok of {} and name of {:?} all is {:?}", id, name_ok, String::from_utf16(&caps.szPname), &caps);
}
}