COM 事件需要 C3702 atl
C3702 atl is required for com events
我的源代码中遇到错误">com 事件需要 C3702 atl",但没有什么可以帮助我解决这个问题。
在 stafx.h 或 .h 文件中包含这些标头不起作用:
#include <comdef.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
在 stdafx.h 或 .h 文件中注释和取消注释此行确实有效://使用命名空间 ATL;
在 stdafx.h 或 .h 文件中添加以下行不起作用:#define _ATL_ATTRIBUTES 1
在 MFC 中添加 ATL 支持也对我不起作用。
CoInitialize(NULL( 和 CoUninitialize((也写在 main 中,但未解决
注释此行会更改错误性质,但没有解决方案://[event_receiver(com(]此行导致编译器错误 C3731(不兼容的事件"function1"和处理程序"function2";事件源和事件处理程序必须为同一类型(
.H 文件
#define _ATL_ATTRIBUTES 1
#pragma once
#include "stdafx.h"
[event_receiver(com)]
class CMainDlg
{
public:
CMainDlg() {};
~CMainDlg() {};
public:
bool OnCallStart();
HRESULT AbtoPhone_OnInitialized(BSTR Msg);
void HookPhoneEvents(IAbtoPhone* pSource);
void UnHookPhoneEvents(IAbtoPhone* pSource);
};//CMainDlg
CPP 文件
#include "stdafx.h"
#include "MainDlg.h"
bool CMainDlg::OnCallStart()
{
HRESULT hr = m_AbtoPhone.CreateInstance(__uuidof(CAbtoPhone));
if (FAILED(hr))
{
AfxMessageBox(_T("Can't load CAbtoPhone component.nCheck is registered 'SIPVoIPSDK.dll'"));
}
HookPhoneEvents(m_AbtoPhone);
return true;
}
void CMainDlg::HookPhoneEvents(IAbtoPhone* pSource)
{
__hook(&_IAbtoPhoneEvents::OnInitialized, pSource, &CMainDlg::AbtoPhone_OnInitialized);
}
void CMainDlg::UnHookPhoneEvents(IAbtoPhone* pSource)
{
__unhook(pSource);
}
HRESULT CMainDlg::AbtoPhone_OnInitialized(BSTR Msg)
{
return S_OK;
}
我正在使用Microsoft Visual Studio 2017社区版。
你解决它的方法是正确的。 必须定义_ATL_ATTRIBUTES。
但是你在 #innclude"stdafx.h"之前更改代码时做到了这一点
#define _ATL_ATTRIBUTES 1
#pragma once
#include "stdafx.h"
只要使用预编译标头,"stdafx.h"#include 之前的所有语句都将被忽略。你必须在stdafx.h中做到这一点!(即使你写道这行不通,你也没有告诉我们为什么......
相关文章:
- ATL::CComContainedObject<contained>: C2259 无法实例化抽象类
- ATL OLE DB Consumer Templates 与 Microsoft OLE DB Driver for
- 在Visual Studio 2017上使用VC++ 2015工具链时缺少ATL标头
- C++ ATL | 找不到_InternalQueryInterface标识符
- 迁移到 Visual Studio 2015 时 ATL 不起作用
- COM 事件需要 C3702 atl
- ATL COM - EnumWindows 回调函数不适用于 IDispatch::Invoke
- C++COM ATL VariantChangeType 会导致 WSH 崩溃
- WinAPI - GetLastError 在通过 COM ATL DLL 调用时始终返回 0
- MFC/DLL中缺少ATL :: CSTRINGT功能,该功能与Clang/vs-2019构建
- 如何使用 ATL/MSOLEDBSQL 启用连接资源池
- 如何将atl :: cimage转换为cv :: mat
- 错误 C4839:非标准地使用类 'ATL::CW2AEX<520>' 作为可变参数函数的参数
- 如何在ATL项目中使用ActiveX DLL
- 我有一个启用了代理存根支持的 ATL 项目,在哪里可以找到 xdlldata.h 文件中所有方法的实现
- 如何在 ATL COM 模块中打印控制台输出
- 将文本日期和时间转换为 ATL::CTime
- MFC vs ATL for ActiveX
- 带有ATL子类的Windows 10 64位上的随机崩溃
- Visual Studio 2015:如何构建针对Visual C V120的ATL项目