c++ - COM function returns E_POINTER -


as newbie hard learn com concept.please explain me following error.why happening have com code following function body.

stdmethodimp ccollectionbase::put_inputcollectioninterface(     iunknown *inputtaginterface) {     icollection* inputcollectioninterface;     hresult hr = queryinterface(__uuidof(icollection),         (void**)&inputcollectioninterface);     if (failed(hr)) return hr;      //m_inputcollectioninterface  global variable of icollection         m_inputcollectioninterface = inputcollectioninterface;     return s_ok; } 

and calling function in following way.

itag* inputtaginterface; //internalcollection icollectionbase object hr = internalcollection->put_inputcollectioninterface(inputtaginterface); 

but hr e_pointer. why e_pointer?

"garbage in, garbage out", pass random pointer function, wrong call inside, expect weird things back.

incorrect things are:

stdmethodimp ccollectionbase::put_inputcollectioninterface(     iunknown *inputtaginterface) {     icollection* inputcollectioninterface;     // 1. calling queryinterface() on wrong object,     //    going query interface of     //    interest of argument pointer     if (!inputtaginterface) return e_nointerface;     hresult hr = inputtaginterface->queryinterface(           __uuidof(icollection), (void**)&inputcollectioninterface);     if (failed(hr)) return hr;      //m_inputcollectioninterface  global variable of icollection     m_inputcollectioninterface = inputcollectioninterface;     return s_ok; }  itag* inputtaginterface; // 2. need initialize value here make sure passing //    valid non-null argument below hr = internalcollection->put_inputcollectioninterface(inputtaginterface); 

since e_pointer coming ccollectionbase::queryinterface method, suppose have other issues on code did not quote.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -