c++ - Data being lost when sent via a different thread over COM server - previously worked in VC6, now broken in VS2010 -


i have been bit lot of little problems in conversion vc6 vs2010, having problems solving one. below delegate used when sending data class com server.

edit 2: added code check varresult.

hresult fire_msg(bstr msg) {     ccomvariant varresult;     t* pt = static_cast<t*>(this);     int nconnectionindex;     ccomvariant* pvars = new ccomvariant[1];      int nconnections = m_vec.getsize();      (nconnectionindex = 0; nconnectionindex < nconnections; nconnectionindex++)     {         pt->lock();         ccomptr<iunknown> sp = m_vec.getat(nconnectionindex);         pt->unlock();         idispatch* pdispatch = reinterpret_cast<idispatch*>(sp.p);         if (pdispatch != null)         {             pvars[0] = msg;             dispparams disp = { pvars, null, 1, 0 };             pdispatch->invoke(0x1, iid_null, locale_user_default, dispatch_method, &disp, &varresult, null, null);         }     }      delete [] pvars;      // changed display happens varresult.     if (varresult.scode != s_ok)     {         // error handling...  (later)         return varresult.scode;     }     else     {         return varresult.scode;     } } 

edit 2: either working or non-working, varresult returns s_ok. no difference.

when break on line, when sent main process or thread, data looks correct:

pdispatch->invoke(0x1, iid_null, locale_user_default, dispatch_method, &disp, null, null, null); 

edit: have pictures of working , non-working. shows when called thread started threadex, data set in "disp" , there no problem doing "pdispatch->invoke".. working: working

non-working: nonworking :end edit

in other application, have following code answer dispatched data:

begin_dispatch_map(cgenrtevent, ccmdtarget)     //{{afx_dispatch_map(cgenrtevent)     disp_function(cgenrtevent, "onmsgstr", onmsgstr, vt_empty, vts_bstr)     disp_function(cgenrtevent, "onmsg", onmsg, vt_empty, vts_bstr)     disp_function(cgenrtevent, "onendrun", onendrun, vt_empty, "")     disp_function(cgenrtevent, "onprogress", onprogress, vt_empty, vts_i4 vts_bstr)     disp_function(cgenrtevent, "onisocket", onisocket, vt_empty, vts_bstr) //  disp_function(cgenrtevent, "onmsg", onmsg, vt_empty, vts_pvariant)     //}}afx_dispatch_map end_dispatch_map()  begin_interface_map(cgenrtevent, ccmdtarget)     interface_part(cgenrtevent, diid__igenrtevents, dispatch) end_interface_map()  void cgenrtevent::onmsgstr(lpctstr strmsg)  {     m_pframe->onmsgstr(strmsg); } 

when used main thread (inside first application), onmsgstr raised. when done different thread, onmsgstr never raised. had been working solidly in vc6, vs2010 doesn't it.

edit: question is, how can prevent data being lost? sure reason tied calling different thread, don't know how fix it.

any suggestions or input appreciated?

thanks in advance.

with paulo madeira's generous help, able solve searching kb280512 led me project called gpscom written pj naughter. link here http://www.naughter.com/gpscom2.html. downloaded code , offers freeware file named "atlcpimplmt.h" use in form long unmodified. based on example, modified code follows:

hresult fire_msg(bstr msg) {     ccomcritseclock<ccomautocriticalsection> lock(m_cpmtcritsec);      atl::ccomvariant varresult;     int nconnections = m_clients.getsize();      int nconnectionindex;     atl::ccomvariant* pvars = new atl::ccomvariant[1];      (nconnectionindex = 0; nconnectionindex < nconnections; nconnectionindex++)     {         atl::ccomptr<idispatch> sp;         if (succeeded(getinterfaceat(nconnectionindex, sp)))         {             variantclear(&varresult);             pvars[0] = msg;             dispparams disp = { pvars, null, 1, 0 };             sp->invoke(0x1, iid_null, locale_user_default, dispatch_method, &disp, &varresult, null, null);             if (varresult.scode != s_ok)             {                 // error handling...  (later)                 return varresult.scode;             }         }     }     delete [] pvars;     return varresult.scode; } 

this question possible duplicate of 1 asked here: atl com: access event methods other thread. fair, when started searching - wasn't aware of right words search. thanks.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -