求救 ATL中实现多线程访问在工作线程中触发事件
int nConnections = m_vec.GetSize(); //当访问到这里后程序一点提示都没有关闭了
搞了一天不知道,到底该怎么改写,希望大侠们帮下
#ifndef _DCC_H_
#define _DCC_H_
#include "ATLCPImplMT.h"template <class T>
class CProxy_IDCWBEvents : public IConnectionPointImplMT<T, &DIID__IDCWBEvents, CComDynamicUnkArray>
{
public: void Fire_OnEditAcx(long wUID)
{
CComVariant varResult;
T* pT = static_cast<T*>(this);
int nConnectionIndex;
CComVariant* pvars = new CComVariant[1];
int nConnections = m_vec.GetSize(); //当访问到这里后程序一点提示都没有关闭了
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
pT->Unlock(); CComQIPtr< IDispatch, &IID_IDispatch > pDispatch( sp.p ); if (pDispatch.p != NULL)
{
VariantClear(&varResult);
pvars[0] = wUID;
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x47, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
}
}
delete[] pvars;
}};
#endif
int nConnections = m_vec.GetSize(); //当访问到这里后程序一点提示都没有关闭了
搞了一天不知道,到底该怎么改写,希望大侠们帮下
#ifndef _DCC_H_
#define _DCC_H_
#include "ATLCPImplMT.h"template <class T>
class CProxy_IDCWBEvents : public IConnectionPointImplMT<T, &DIID__IDCWBEvents, CComDynamicUnkArray>
{
public: void Fire_OnEditAcx(long wUID)
{
CComVariant varResult;
T* pT = static_cast<T*>(this);
int nConnectionIndex;
CComVariant* pvars = new CComVariant[1];
int nConnections = m_vec.GetSize(); //当访问到这里后程序一点提示都没有关闭了
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
pT->Unlock(); CComQIPtr< IDispatch, &IID_IDispatch > pDispatch( sp.p ); if (pDispatch.p != NULL)
{
VariantClear(&varResult);
pvars[0] = wUID;
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x47, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
}
}
delete[] pvars;
}};
#endif
解决方案 »
- 路径格式判断
- 一幅大的图像文件(文件大,图像也大),我要把它缩小,再另存为一个小的文件(文件小,图像也小)!
- 跪求高手帮助!~~~~图像处理的问题
- #error Please use the /MD switch for _AFXDLL builds,vs2005
- 编译的问题//一重编译就出错
- 如何在对话框窗口中添加菜单
- 关于SendMessage()的不理解的问题???????????
- 动态生成控件问题
- wordXP的符号栏被禁用了
- 高手请帮忙,关于CListCtrl的问题。
- MyProject.exe 中的 0x787a3fed (mfc90d.dll) 处未处理的异常
- 怎么把数据库的数据保存到结构体中
为什么我没法使用???都是跑到这里 没一点反应程序就关闭了
void Fire_OnEditAcx(long wUID)
{
int nConnectionIndex;
CComVariant* pvars = new CComVariant[1];
int nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
CComPtr<IUnknown> sp;
sp.Attach (GetInterfaceAt(nConnectionIndex)); IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch != NULL)
{
pvars[0] = wUID;
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x47, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
}
}
delete[] pvars;
}
为什么我没法使用???都是跑到这里 没一点反应程序就关闭了
没反应程序就关闭了, 这是程序出了异常, 调试器应该捕捉到, 你看看VC的Outpout窗口, 看有没有异常信息, 针对问题去调试
http://topic.csdn.net/t/20030822/18/2178342.html这个路径就刷如何在Alt中实现多线程激发事件
http://www.codeguru.com/Cpp/COM-Tech/atl/atl/article.php/c75
下边是我实现的代码,这边错误没出现,但是
:\TDdownload\ATLCPImplMT.h(232) : error C2440: 'type cast' : cannot convert from 'class ATL::CComPtr<struct IUnknown>' to 'unsigned long'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(61) : while compiling class-template member function 'struct IUnknown *__thiscall IConnectionPointImplMT<class CCCWB,&struct _GUID const DIID__IDCWBEvents,class CComDynamicUnkArra错误指在ATLCPImplMT.h代码红色部分
template <class T, const IID* piid, class CDV>
LPUNKNOWN IConnectionPointImplMT<T, piid, CDV>::GetInterfaceAt(
int nConnectionIndex)
{
m_CPMTCritSec.Lock(); LPUNKNOWN pUnk = NULL;
// IConnectionPointImplMT Vector stores DWORDs instead of IUnknown pointers,
// explicit cast required:
;
DWORD dwGITCookie = (DWORD)(m_vec.GetAt(nConnectionIndex)); if (dwGITCookie != NULL)
{
IID iid;
GetConnectionInterface(&iid);
HRESULT hr = m_pGIT->GetInterfaceFromGlobal(
dwGITCookie, iid, reinterpret_cast<void **>(&pUnk));
ATLASSERT(hr == S_OK);
} m_CPMTCritSec.Unlock(); return pUnk;
}#ifndef _DCC_H_
#define _DCC_H_
#include "ATLCPImplMT.h"
#include "CEventProxy.h"template <class T>
class CProxy_IDCWBEvents : public IConnectionPointImplMT<T, &DIID__IDCWBEvents, CComDynamicUnkArray_GIT>
{
public: void Fire_OnEditAcx(long wUID)
{
CComVariant varResult;
T* pT = static_cast<T*>(this);
int nConnectionIndex;
CComVariant* pvars = new CComVariant[1];
int nConnections = m_vec.GetSize(); //当访问到这里后程序一点提示都没有关闭了
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
pT->Unlock(); CComQIPtr< IDispatch, &IID_IDispatch > pDispatch( sp.p ); if (pDispatch.p != NULL)
{
VariantClear(&varResult);
pvars[0] = wUID;
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x47, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
}
}
delete[] pvars;
}};
#endif
LPUNKNOWN IConnectionPointImplMT<T, piid, CDV>::GetInterfaceAt(
int nConnectionIndex)
{
m_CPMTCritSec.Lock();LPUNKNOWN pUnk = NULL;
// IConnectionPointImplMT Vector stores DWORDs instead of IUnknown pointers,
// explicit cast required:
;
DWORD dwGITCookie = (DWORD)(m_vec.GetAt(nConnectionIndex)); if (dwGITCookie != NULL)
{
IID iid;
GetConnectionInterface(&iid);
HRESULT hr = m_pGIT->GetInterfaceFromGlobal(
dwGITCookie, iid, reinterpret_cast<void **>(&pUnk));
ATLASSERT(hr == S_OK);
}m_CPMTCritSec.Unlock(); return pUnk;
}
#ifndef _VBMHWBCP_H_
#define _VBMHWBCP_H_
//#include "ATLCPImplMT.h" 应该注释掉
#include "CEventProxy.h"
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
EventSink.cpp
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
vbMHWB.cpp
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
vbWB.cpp
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vncc.h(1981) : see reference to class template instantiation 'CProxy_IDCWBEvents<T>' being compiled
F:\TDdownload\vncc.h(7) : error C2504: 'IConnectionPointImplMT' : base class undefined
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2143: syntax error : missing ',' before '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
F:\TDdownload\vncc.h(7) : error C2059: syntax error : '<'
F:\TDdownload\vbMHWB\vbWB.h(565) : see reference to class template instantiation 'CProxy_IDCWBEvents<class TcWB>' being compiled
Generating Code...
Error executing cl.exe.
Creating browse info file...