3 ms·
I recently had need to write some native Windows software, and I did want to use Rust initially, since I don't fully trust myself to write correct C++. I ended
by Eridrus 11y ago
I recently had need to write some native Windows software, and I did want to use Rust initially, since I don't fully trust myself to write correct C++.
I ended up still writing it in C++ since Rust's support for writing COM objects/servers was not great, but I also ended up having to chase down a bug where I forgot to AddRef before storing a COM pointer in a map.
- lqdc13 11y agoI also had to do that recently and used Nim instead after spending too much time on it in C. For anyone attempting to do the same, I suggest 32bit Nim + msys2 + nimble install oldwinapi.
- pjmlp 11y agoWhy did you not make use of CComPtr, ComPtr or the _com_ptr_t smart pointers? https://msdn.microsoft.com/en-us/library/ezzw7k98.aspx https://msdn.microsoft.com/en-us/library/ezzw7k98.aspx https://msdn.microsoft.com/en-us/library/br244983.aspx https://msdn.microsoft.com/en-us/library/br244983.aspx https://msdn.microsoft.com/en-us/library/5yb2sfxk.aspx https://msdn.microsoft.com/en-us/library/5yb2sfxk.aspx https://msdn.microsoft.com/en-us/library/h31ekh7e.aspx https://msdn.microsoft.com/en-us/library/h31ekh7e.aspx
- Eridrus 11y agoI did use CComPtr, but they only reduce the amount of footguns, they don't get rid of them. In my case, I accidentally stored a reference to the inner pointer instead of calling Detach. My point isn't that there aren't nice idiomatic ways of writing nice windows/c++ code that are not fragile, it's that unless you're well versed in them, you can easily screw things up pretty badly. [EDIT]: In case it's not clear, I am not a windows C++ developer, I've read a decent amount of windows C++ code, so I sort of know what's going on, but I've written less than 5k lines of windows C/C++ in my life.
- pjmlp 11y agoFare enough. I know Windows since Win16 APIs days (started with Windows 3.0) I would run into similar issues when coding for Apple platforms, for example.