Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion win32/dll/user32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod wndclass;
pub use builtin::DLL;

pub use menu::HMENU;
pub use message::{MSG, WM};
pub use message::{MSG, WM, dispatch_message};
pub use misc::HINSTANCE;
// Used by comctl32.
pub use misc::{TRACKMOUSEEVENT, TrackMouseEvent};
Expand Down
1 change: 1 addition & 0 deletions win32/dll/winmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2024"

[dependencies]
bitflags = { workspace = true }
builtin-user32 = { path = "../user32" }
log = { workspace = true }
memory = { workspace = true }
win32-derive = { workspace = true }
Expand Down
20 changes: 15 additions & 5 deletions win32/dll/winmm/src/wave.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{MMRESULT, get_state};
use bitflags::bitflags;
use builtin_user32::{MSG, dispatch_message};
use memory::{Extensions, ExtensionsMut};
use std::{collections::VecDeque, sync::Arc};
use win32_system::{Event, System, Wait, host};
Expand All @@ -15,6 +16,7 @@ pub struct WaveState {
#[derive(Clone)]
enum Notify {
Function(u32, u32),
Window(HWND, u32),
}

enum MM_WOM {
Expand Down Expand Up @@ -98,6 +100,18 @@ pub async fn retrowin32_wave_thread_main(sys: &mut dyn System, hwo: HWAVEOUT) {
)
.await;
}
Some(Notify::Window(hwnd, instance)) => {
let msg = MSG {
hwnd: hwnd,
message: MM_WOM::DONE as u32,
wParam: instance,
lParam: wave_hdr_addr,
time: 0,
pt_x: 0,
pt_y: 0,
};
dispatch_message(sys, &msg).await;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This executes the message handler in the current x86 thread, which (from the name of the function you're in) you can see is the multimedia thread. That is, all the winmm functionality is supposed to happen on this winmm thread and the different callbacks it makes (with the exception of the function callback, I think?) are supposed to go onto the caller's thread.

Concretely, I think that means this should put this message in the target's message queue, rather than dispatching it. Take a look at PostMessage's impl

get_state(sys).messages.push(MSG {

I think maybe the way I'd do it is to change that PostMessage into a wrapper around a post_message() function that accepts a MSG and then call it from here.

}
None => {}
}
}
Expand Down Expand Up @@ -216,12 +230,8 @@ pub fn waveOutOpen(

let notify = match fdwOpen.callback {
CALLBACK::NULL => None,
CALLBACK::WINDOW => {
let hwnd = HWND::from_raw(dwCallback);
log::warn!("TODO: waveOutOpen callback with window={hwnd:?}");
None
}
CALLBACK::FUNCTION => Some(Notify::Function(dwCallback, dwInstance)),
CALLBACK::WINDOW => Some(Notify::Window(HWND::from_raw(dwCallback), dwInstance)),
_ => todo!("callback {:?}", fdwOpen.callback),
};

Expand Down
Loading