11//! [`output!`] macro to log messages via the Debug API, to be viewed in e.g.
22//! [DebugView](https://learn.microsoft.com/en-us/sysinternals/downloads/debugview).
3- use :: winapi:: um:: debugapi:: { OutputDebugStringA , OutputDebugStringW } ;
3+ use windows:: Win32 :: System :: Diagnostics :: Debug :: { OutputDebugStringA , OutputDebugStringW } ;
4+ use windows:: core:: { PCSTR , PCWSTR } ;
45
56macro_rules! output {
67 ( $fmt: literal $( , $args: expr) * $( , ) ?) => { {
@@ -36,22 +37,18 @@ fn encode_unicode(msg: &str) -> Vec<u16> {
3637/// version may be slightly faster.
3738pub ( crate ) fn output_debug_string_w ( msg : & str ) {
3839 let v: Vec < u16 > = encode_unicode ( msg) ;
39- let p: * const u16 = v. as_ptr ( ) ;
40+ let p = PCWSTR :: from_raw ( v. as_ptr ( ) ) ;
4041 unsafe { OutputDebugStringW ( p) } ;
4142 // paranoia: ensure `v` is valid until after `OutputDebugStringW`
4243 drop ( v) ;
4344}
4445
45- fn encode_ascii ( msg : & str ) -> Vec < i8 > {
46+ fn encode_ascii ( msg : & str ) -> Vec < u8 > {
4647 const ZF : & [ u8 ] = b"[ZF] " ;
4748 let msg = msg
4849 . chars ( )
4950 . map ( |c| if c. is_ascii ( ) { c as u8 } else { b'?' } ) ;
50- ZF . iter ( )
51- . copied ( )
52- . chain ( msg. chain ( Some ( 0 ) ) )
53- . map ( |b| b as i8 )
54- . collect ( )
51+ ZF . iter ( ) . copied ( ) . chain ( msg. chain ( Some ( 0 ) ) ) . collect ( )
5552}
5653
5754/// Output an ASCII debug string.
@@ -61,8 +58,8 @@ fn encode_ascii(msg: &str) -> Vec<i8> {
6158/// Microsoft Unicode ineptness).
6259#[ allow( dead_code, reason = "Use Unicode version by default" ) ]
6360pub ( crate ) fn output_debug_string_a ( msg : & str ) {
64- let v: Vec < i8 > = encode_ascii ( & msg) ;
65- let p: * const i8 = v. as_ptr ( ) ;
61+ let v: Vec < u8 > = encode_ascii ( & msg) ;
62+ let p = PCSTR :: from_raw ( v. as_ptr ( ) ) ;
6663 unsafe { OutputDebugStringA ( p) } ;
6764 // paranoia: ensure `v` is valid until after `OutputDebugStringA`
6865 drop ( v) ;
0 commit comments