rust


Why does removing println! cause a Windows API function called through FFI to fail?


If I remove the println! from the following code, waveOutPrepareHeader returns code MMSYSERR_INVALPARAM.
fn write_audio_block(device: &PlaybackDevice, block: &[u8]) {
use std::mem;
use std::{thread, time};
let mut header: mmsystem::WAVEHDR = unsafe { mem::uninitialized() };
header.dwBufferLength = block.len() as winapi::minwindef::DWORD;
header.lpData = block.as_ptr() as winapi::winnt::LPSTR;
println!("ptr: {:?}\nlength: {:?}", // removing this causes error
header.lpData,
header.dwBufferLength);
let header_size: winapi::minwindef::UINT = mem::size_of::<mmsystem::WAVEHDR>() as u32 +
header.dwBufferLength as u32;
catch_errors(unsafe { winmm::waveOutPrepareHeader(device.handle, &mut header, header_size) });
catch_errors(unsafe { winmm::waveOutWrite(device.handle, &mut header, header_size) });
thread::sleep(time::Duration::from_millis(100));
while unsafe { winmm::waveOutUnprepareHeader(device.handle, &mut header, header_size) } ==
mmsystem::WAVERR_STILLPLAYING {
thread::sleep(time::Duration::from_millis(10));
}
}
Even adding another println! or removing the thread::sleep after waveOutWrite will cause waveOutPrepareHeader to return MMSYSERR_INVALPARAM.
Otherwise it works fine.

Related Links

What is the usage of the asterisk symbol in Rust?
Convert Arc<RwLock> to &mut
Cargo build results in “No match for id”
Cargo fails because the peer certificate cannot be authenticated with given CA certificates on SLES11
How to group 'Option' assignments in Rust?
Exclude dependencies when running Clippy
How to create a new empty Tree
How to access a vector multiple times within an 'Option'?
Iterator on Option<Vec<>>
Literal out of range warning when iterating over all values of u8
How to write a trait that has a method returning a reference and implement it correctly?
Mismatched types when displaying a matrix with a for loop
How to have a struct field with the same mutability as the parent struct?
`if` condition remains borrowed in body [duplicate]
“parameter `'a` is never used” error when 'a is used in type parameter bound
Linking Rust application with a dynamic library not in the runtime linker search path

Categories

HOME
memory
softlayer
openlayers-3
typeerror
autocomplete
moodle-api
material-components
apache-kafka-connect
phpmqtt
u-boot
phpseclib
wine
reportviewer
xamarin-zebble
circleci
xbap
live-streaming
trace32
cocos2d-android
varnish-vcl
opam
el
sharedpreferences
kamailio
quartz.net
animated-gif
unordered-multimap
boolean-logic
tsung
bitbake
region
fotorama
osx-lion
quickcheck
mongoengine
xmlunit
rails-postgresql
elastica
opal-framework
haar-classifier
minikube
reverse-dns
nomad
destroy
gcal
adblock
webalizer
md5-file
head.js
comm
stateless-session-bean
rcharts
fitbit
oracle-fusion-apps
callouts
fragmentstatepageradapter
declarative
piping
node.js-connect
powerpoint-2013
timestamping
onepage-checkout
webgrind
perceptron
largenumber
place
directx-9
libz
uitest
cache-manifest
kotlin-android-extensions
python-c-extension
pass-by-value
mojo
fasterxml
datagridcomboboxcolumn
wicket-1.5
qt5.4
csslint
cpu-time
pre
usb-flash-drive
principalcontext
spring-security-acl
vlab
illuminate-container
acitree
unrealscript
stty
django-facebook
acceptance-testing
eager-loading
user-forums
clrprofiler
voice-recording
taskkill
jdom
monocross
mkannotation
fbml
infopath-2007
will-paginate
radscheduler
simile
anonymous-types
chunking
pinax
raw-data
cleartype

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App