Git Product home page Git Product logo

Comments (6)

sylveon avatar sylveon commented on August 26, 2024 1

I've created #93 which adds put_void() and put_unknown() to com_ptr and allows you to pass a CLSID to wil::CoCreateInstance.

from wil.

zomgrolf avatar zomgrolf commented on August 26, 2024

Wow, that was quick, awesome!
I like the new overloads for CoCreateInstance -- now my code will look much nicer.

The new put_void member fn matches other smart COM pointers, so it makes transition a bit easier, so that's also nice. I wonder about put_unknown -- IUnknown is the base interface, but in some cases com calls do return other interfaces, e.g. ID2D1Factory::CreateWicBitmapRenderTarget returns ID2D1RenderTarget, where you might actually want to hold ID2D1BitmapRenderTarget. So, I'm thinking it might be better to have a member function template, say put_as<T> (with a better name though!), that does the reinterpret_cast, possibly with an extra check to ensure that T is the base class of whatever interface is held by the smart pointer?

from wil.

sylveon avatar sylveon commented on August 26, 2024

Wow talk about consistency :/
Since this is still a PR, would you be fine with just put_as<void> instead of put_void?

from wil.

zomgrolf avatar zomgrolf commented on August 26, 2024

Absolutely! Whatever you think is best.
Just pointing out, that a separate put_void is consistent with com_ptr::put_void in WinRT, so that's one less search & replace when switching between the two. Personally, I don't care about that (at all), so feel free to get rid of it...

from wil.

sylveon avatar sylveon commented on August 26, 2024

but in some cases com calls do return other interfaces, e.g. ID2D1Factory::CreateWicBitmapRenderTarget returns ID2D1RenderTarget, where you might actually want to hold ID2D1BitmapRenderTarget.

After rereading don't think this is a great idea. You should use an wil::com_ptr<ID2D1RenderTarget> and use QueryInterface after the call to make sure it is actually an ID2D1BitmapRenderTarget, because you never know when that implementation detail may be changed.

from wil.

zomgrolf avatar zomgrolf commented on August 26, 2024

That's a very good point! In that case, there's nothing else to be added to your fix, I think.
Thanks!

from wil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.