diff --git a/src/primitives/istringwriter.rs b/src/primitives/istringwriter.rs deleted file mode 100644 index 1a1d4a5..0000000 --- a/src/primitives/istringwriter.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::primitives::{IUnknown, IUnknownVtbl, Interface, GUID, HRESULT}; -use std::{ffi::c_void, ops::Deref}; -use windows::core::BSTR; - -#[repr(C)] -pub struct _StringWriter { - pub vtable: *const _StringWriterVtbl, -} - -#[repr(C)] -pub struct _StringWriterVtbl { - pub parent: IUnknownVtbl, - pub GetTypeInfoCount: *const c_void, - pub GetTypeInfo: *const c_void, - pub GetIDsOfNames: *const c_void, - pub Invoke: *const c_void, - pub ToString: unsafe extern "system" fn(this: *mut c_void, pRetVal: *mut *mut u16) -> HRESULT, -} - -impl _StringWriter { - pub fn to_string(&self) -> Result { - let mut buffer = BSTR::new(); - - let hr = unsafe { (*self).ToString(&mut buffer as *mut _ as *mut *mut u16) }; - - if hr.is_err() { - return Err(format!("Failed while running `ToString`: {:?}", hr)); - } - - Ok(buffer.to_string()) - } - - #[inline] - pub unsafe fn ToString(&self, pRetVal: *mut *mut u16) -> HRESULT { - ((*self.vtable).ToString)(self as *const _ as *mut _, pRetVal) - } -} - -impl Interface for _StringWriter { - const IID: GUID = GUID::from_values( - 0xcb9f94c0, - 0xd691, - 0x3b62, - [0xb0, 0xb2, 0x3c, 0xe5, 0x30, 0x9c, 0xfa, 0x62], - ); - - fn vtable(&self) -> *const c_void { - self.vtable as *const _ as *const c_void - } -} - -impl Deref for _StringWriter { - type Target = IUnknown; - - #[inline] - fn deref(&self) -> &IUnknown { - unsafe { &*(self as *const _StringWriter as *const IUnknown) } - } -} diff --git a/test/source/WithArgs/Program.cs b/test/source/WithArgs/Program.cs index ec89b85..b7f8ab8 100644 --- a/test/source/WithArgs/Program.cs +++ b/test/source/WithArgs/Program.cs @@ -1,6 +1,8 @@ using System; using System.IO; using System.Reflection; +using System.Threading; +using System.Threading.Tasks; namespace WithArgs { @@ -17,6 +19,10 @@ namespace WithArgs Console.WriteLine($"___ ({s.Length}) {s}"); } + Console.Error.WriteLine("[!] If I had any errors, they would be here, in `stderr`!"); + + Console.WriteLine("[*] Bye!"); + Console.WriteLine(); } } diff --git a/test/source/WithArgs/WithArgs.csproj b/test/source/WithArgs/WithArgs.csproj index 018fa47..bfbcefc 100644 --- a/test/source/WithArgs/WithArgs.csproj +++ b/test/source/WithArgs/WithArgs.csproj @@ -1,7 +1,6 @@  - + Debug AnyCPU @@ -10,7 +9,7 @@ Properties WithArgs WithArgs - v4.0 + v4.5 512 true @@ -78,15 +77,15 @@ with_args_x64 - - - - + + + + - - + + - + diff --git a/test/source/WithExit/Program.cs b/test/source/WithExit/Program.cs index 542e02e..f68275e 100644 --- a/test/source/WithExit/Program.cs +++ b/test/source/WithExit/Program.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using System.Threading; namespace WithExit { @@ -15,6 +16,10 @@ namespace WithExit Environment.Exit(-1); Console.WriteLine("[!] I am still alive!"); + Console.Error.WriteLine("[!] If I had any errors, they would be here, in `stderr`!"); + + Console.WriteLine("[*] Bye!"); + Console.WriteLine(); } } diff --git a/test/source/WithoutArgs/Program.cs b/test/source/WithoutArgs/Program.cs index 82af19e..992f90f 100644 --- a/test/source/WithoutArgs/Program.cs +++ b/test/source/WithoutArgs/Program.cs @@ -11,6 +11,8 @@ namespace WithoutArgs Console.WriteLine($"[*] Hello World from `{Assembly.GetExecutingAssembly().FullName}`!"); Console.WriteLine($"[*] I am running in `{AppDomain.CurrentDomain}`!"); Console.WriteLine("[*] I have no arguments and live a happy life!"); + Console.Error.WriteLine("[!] But if I didn't live a happy life, all my error would be here, in `stderr`!"); + Console.WriteLine("[*] Bye!"); Console.WriteLine();