queryinterface

Could QueryInterface() provide us with nullptr when succeed? [duplicate]

你离开我真会死。 提交于 2019-12-24 11:26:58
问题 This question already has answers here : Handling CoCreateInstance return value (2 answers) Closed 5 years ago . Imagine a situation: CComPtr<IGraphBuilder> pGraph; HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pGraph)); if (SUCCEEDED(hr)) { CComPtr<IMediaControl> pControl; hr = pGraph->QueryInterface(IID_PPV_ARGS(&pControl)); if(SUCCEEDED(hr)) {...} } I wonder, if pControl could ever be nullptr inside last block {...} . The question occurred,

Handling CoCreateInstance return value

五迷三道 提交于 2019-12-19 23:26:28
问题 Here's a code sample creating a COM object: CComPtr<IBaseFilter> pFilter; auto hr = CoCreateInstance(CLSID_DMOWrapperFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pFilter)); I've seen somewhere that checking if CoCreateInstance() succeeded should look like this: if (SUCCEEDED(hr) && pFilter != nullptr) { // code goes here } What if I would check only hr ? Wouldn't it be enough? Should I also check that filter != nullptr ? //would this be enough? if (SUCCEEDED

How do Powershell query interface on a COM object

大城市里の小女人 提交于 2019-12-08 16:03:36
问题 I created a COM object using Powershell: $obj = new-object -com MyLib.MyObj Then I need to query the interface "MyLib.MyInterface" on that object, but I have no idea how to do it with PowerShell. In order word suppose I have the below C++ code CComPtr<IInterface1> pInterface1; CComPtr<IInterface2> pInterface2; pInterface1->CoCreateInstance(CLSID_XXXX); //in PowerShell: $obj = new-object -com MyLib.MyObj pInterface1->QueryInterface(IID_YYYY, &pInterface2); //how to do this in PowerShell? How

fuzzy search with active record query interface

三世轮回 提交于 2019-12-08 02:32:23
问题 I have a fuzzy search in my rails app, which sql what I want is this: select * from `user` where name like '%abc%' I've tried to do it like this: name = 'abc' User.where("name like '%?%'", name) It failed, in console it logged: select * from `user` where name like '%'abc'%' Finally I tried this name = 'abc' User.where("name like ?", '%' + name + '%') It worked. But I think it doesn't like rails way, is there any better way to do that? 回答1: User.where("name REGEXP ?", 'regex_str') and regex

Access violation casting IDispatch in XE2

非 Y 不嫁゛ 提交于 2019-12-06 06:22:27
问题 We're using some old code (ComLib.pas created by Binh Ly) so we can use the enumeration interface on an (OleVariant) object: type TDispNewEnum = dispinterface ['{97079E31-6957-11D2-9154-0000B4552A26}'] // dummy property _NewEnum: IUnknown readonly dispid -4; // DISPID_NEWENUM function _NewEnumFunc: IUnknown; dispid -4; // DISPID_NEWENUM end; procedure TEnumVariant.AttachUnknown (const Unk: IUnknown); var pDisp: IDispatch; _NewEnumPropFailed: boolean; Unknown: IUnknown; begin Detach; Unknown :

What is IconnectionPoint and EventHandling

断了今生、忘了曾经 提交于 2019-12-06 01:55:02
Trying to understand What is IConnectionPoint and how this is connected to IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections and EventHandling . Read the artcicles from MSDN and CodeProject which is explaining a about other methods like: QueryInterface() and otherthings. I am unable to figure out how all these things( IConnectionPointContainer,IEnumConnectionPoints,IEnumConnections ) are interconnected with eachother and event Handling. I just want to create a simpleClient which Will trigger an event in COM object. If there are any articles or code snippet that can explain how

Access violation casting IDispatch in XE2

白昼怎懂夜的黑 提交于 2019-12-04 12:24:10
We're using some old code (ComLib.pas created by Binh Ly) so we can use the enumeration interface on an (OleVariant) object: type TDispNewEnum = dispinterface ['{97079E31-6957-11D2-9154-0000B4552A26}'] // dummy property _NewEnum: IUnknown readonly dispid -4; // DISPID_NEWENUM function _NewEnumFunc: IUnknown; dispid -4; // DISPID_NEWENUM end; procedure TEnumVariant.AttachUnknown (const Unk: IUnknown); var pDisp: IDispatch; _NewEnumPropFailed: boolean; Unknown: IUnknown; begin Detach; Unknown := Unk; { extract IEnumVariant } if (Unknown <> nil) then begin { try IEnumVariant } if not (Succeeded

Handling CoCreateInstance return value

别等时光非礼了梦想. 提交于 2019-12-01 19:00:54
Here's a code sample creating a COM object: CComPtr<IBaseFilter> pFilter; auto hr = CoCreateInstance(CLSID_DMOWrapperFilter, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pFilter)); I've seen somewhere that checking if CoCreateInstance() succeeded should look like this: if (SUCCEEDED(hr) && pFilter != nullptr) { // code goes here } What if I would check only hr ? Wouldn't it be enough? Should I also check that filter != nullptr ? //would this be enough? if (SUCCEEDED(hr)) { // code goes here } This question also concerns other COM methods like QueryInterface() . Having