I am facing ERROR "C3702 atl is required for com events" in my source code but nothing help me to resolve this one.
Including these headers in stafx.h or .h file does not work:
#include <comdef.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
commenting and un commenting this line in stdafx.h or .h file does work:
//using namespace ATL;
Adding below line in stdafx.h or .h file does not work:
#define _ATL_ATTRIBUTES 1
Adding ATL support in MFC also does not work for me.
CoInitialize(NULL) and CoUninitialize() are also written in the main but not solved
Commenting this line change the error nature but no solution:
//[event_receiver(com)]
This line cause Compiler Error C3731 (incompatible event 'function1' and handler 'function2'; event source and event handler must be the same type)
.H File
#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 File
#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;
}
I am using Microsoft Visual Studio 2017 Community edition.
Your way to solve it is correct. _ATL_ATTRIBUTES must be defined.
But you did it in changing code before the #innclude of "stdafx.h"
#define _ATL_ATTRIBUTES 1
#pragma once
#include "stdafx.h"
As long as you use precompiled header all statements before the #include "stdafx.h" are ignored. You must do it in the stdafx.h! (Even you wrote that this doesn't work, you don't told us why...)
Related
Disclaimer: C++ Redefinition Header Files (winsock2.h) doesnt solved my problem
In this project, im trying to take a screenshot and then compressing it with libjpeg-turbo. The problem is that i get errors like
"sockaddr": "struct" Type redefinition
and
"nothl": Redefinition
ScreenWorker.h:
#pragma once
#ifndef SCREENWORKER_H
#define SCREENWORKER_H
#include <string>
#include <vector>
#include <thread>
#include <turbojpeg.h>
#include <Windows.h>
#include "..\API\NetClient.h"
class ScreenWorker {
private:
NetClient* client;
public:
int delay = 30;
ScreenWorker(NetClient* client);
HBITMAP GetScreenBmp(HDC hdc);
void Update();
};
#endif
ScreenWorker.cpp:
#include "ScreenWorker.h"
ScreenWorker::ScreenWorker(NetClient* client) {
this->client = client;
Update();
}
HBITMAP ScreenWorker::GetScreenBmp(HDC hdc) {...}
void ScreenWorker::Update() {...}
The main.cpp (DLL-Entry):
#pragma once
#include "..\..\Base\API\API\GladOSClient.h"
#include "ScreenWorker.h"
using namespace std;
BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, LPVOID Reserved) {
return true;
}
NetClient.h (only Header part):
#pragma once
#ifndef NETCLIENT_H
#define NETCLIENT_H
#define _WINSOCKAPI_
#include <Windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <vector>
#include <list>
#include <mutex>
#include <map>
#include <string>
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
#include "Utils.h"
#include "PacketHandler.h"
#include "Packet.h"
...
#endif
As you can see, i'm using header-guards everywhere, but nevertheless i get those errors. Seems like there is a problem with the including of "Windows.h"?
Thanks in advance!
Edit
I guess the problem has something to do with the way libjpegturbo handles the including of "Windows.h". Currently i have no real way of solving this issue. Maybe im trying exporting the function i need in a seperated DLL... hopefully this will solve it.
Classic issue.
Just remove this line from NetClient.h
#include <Windows.h>
The inclusion of <Winsock2.h> will pull in <windows.h> for you and correct all those redefine issues.
Intro
First of all, I would like to say that I have read through the previous answers for this type of question, including this excellently written one.
However, I do not understand enough about C++ to be able to use the more "advanced" fixes.
I have ensured that the right type of console has been selected (Console (/SUBSYSTEM:CONSOLE) for those interested), and have the required imports with the possible exception of an IDL mentioned somewhere (that falls into the lack of understanding category).
If this is a duplicate, I would be more than happy to use the post I duplicated, but I have not been able to find anything that can help someone of my skill level.
Technical Information
IDE: Visual Studio
Platform: Windows
Code
headers.h
#pragma once
#include <stdio.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <Shobjidl.h>
#include <time.h>
#include <stdlib.h>
#include <tchar.h>
main.cpp
#include "headers.h"
using namespace std;
int main() {
string x = "C://Users/student/Desktop/i-should-buy-a-boat.jpg";
x.c_str();
wstring tempx = std::wstring(x.begin(), x.end());
LPCWSTR sw = tempx.c_str();
HRESULT SetWallpaper(
LPCWSTR monitorID,
LPCWSTR wallpaper
);
SetWallpaper(NULL, sw);
}
SetWallpaper() is not a standalone function exported by the Win32 API. It is a method of the IDesktopWallpaper interface (see here).
So you need to use code that is more like this instead:
#include "headers.h"
int main()
{
std::wstring x = L"C:\\Users\\student\\Desktop\\i-should-buy-a-boat.jpg";
CoInitialize(NULL);
IDesktopWallpaper *p;
if (SUCCEEDED(CoCreateInstance(__uuidof(DesktopWallpaper), 0, CLSCTX_LOCAL_SERVER, __uuidof(IDesktopWallpaper), (void**)&p)))
{
p->SetWallpaper(NULL, x.c_str());
p->Release();
}
CoUninitialize();
return 0;
}
I've been creating codes using C++ STL. And I want to use "queue".
So, I wrote the codes like below.
But, I encountered "queue is not a template" error.
As you can see, I wrote headers related with queue (iostream, queue) in "Common.h" file and wrote include "Common.h" in "DataQueue.h" file. But, VS2013 IDE tool said that 'queue m_deQueue' is error because queue is not a template. I don't know why.. this error occured. Any help is appreciated!
//[Common.h]
#ifndef _COMMON_
#define _COMMON_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
//thread related headers
#include <Windows.h>
#include <process.h>
//socket related headers
#include <winsock.h>
#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#endif
//[DataQueue.h]
#ifndef _QUEUE_
#define _QUEUE_
#include "SocketStruct.h"
#include "Common.h"
class CDataQueue{
private:
static CDataQueue* m_cQueue;
// deque <ST_MONITORING_RESULT> m_deQueue;
queue <ST_MONITORING_RESULT> m_deQueue;
CRITICAL_SECTION m_stCriticalSection;
CDataQueue();
~CDataQueue();
public:
static CDataQueue* getDataQueue(){
if (m_cQueue == NULL){
m_cQueue = new CDataQueue();
}
return m_cQueue;
}
deque <ST_MONITORING_RESULT> getQueue();
void pushDataToQueue(ST_MONITORING_RESULT data);
ST_MONITORING_RESULT popDataFromQueue();
};
#endif
//[DataQueue.cpp]
#include "DataQueue.h"
CDataQueue* CDataQueue::m_cQueue = NULL;
CDataQueue::CDataQueue(){
::InitializeCriticalSection(&m_stCriticalSection);
// m_mutex = PTHREAD_MUTEX_INITIALIZER;
}
CDataQueue::~CDataQueue(){
::DeleteCriticalSection(&m_stCriticalSection);
}
::deque <ST_MONITORING_RESULT> CDataQueue::getQueue(){
return m_deQueue;
}
void CDataQueue::pushDataToQueue(ST_MONITORING_RESULT data){
::EnterCriticalSection(&m_stCriticalSection);
m_deQueue.push_back(data);
::LeaveCriticalSection(&m_stCriticalSection);
}
ST_MONITORING_RESULT CDataQueue::popDataFromQueue(){
::EnterCriticalSection(&m_stCriticalSection);
ST_MONITORING_RESULT data = m_deQueue.front();
m_deQueue.pop_front();
::LeaveCriticalSection(&m_stCriticalSection);
return data;
}
Sitting at the top of the <queue> header from the MS implementaiton of the standard library, we find...
// queue standard header
#pragma once
#ifndef _QUEUE_
#define _QUEUE_
Which means your usage of that identifier for your own header fencepost is precluding the MS header body from being pulled in. Thus, no std::queue for you. Use a different id, preferably something that doesn't violate usage rules for macro constants reserved for the implementation (like this one).
And that, kids, is why we don't use identifiers reserved for implementation usage. For more information, read this question: "What are the rules about using an underscore in a C++ identifier?"
I've included the TlHelp32.h header properly though I keep getting the message:
"Error: identifier "CreateToolhelp32Snapshot" is undefined"
when attempting to use CreateToolhelp32Snapshot. When I used the "peek definition" feature in VS I found that there are errors within this header where in certain areas it says:
"Error expected a ';'"
Any ideas how to fix this?
#include "stdafx.h"
#include <TlHelp32.h>
#include <Windows.h>
#include <iostream>
using namespace std;
class Functions{
public:
void playerHealthPrinter(){
HANDLE hProcess;
DWORD dwPID, dwProtection, dwCaveAddress;
BOOL bPOn, bIOn, bProt;
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
Never include Win32 headers before <windows.h>. The following should work, instead:
#include <Windows.h>
#include <TlHelp32.h> // <-- include *after* windows.h
If it still doesn't work then please post an MCVE including the relevant headers and version of VS.
I tried to make console application that is using my DLL that is taking care of Kinect.
When I am building my project I get:
2>e:\projects\c++\vs\kinect dll\consoleapplication1\consoleapplication1.cpp(4):
warning C4627: '#include "KinectDLL.h"': skipped when looking for precompiled header use
2> Add directive to 'stdafx.h' or rebuild precompiled header
2> e:\michał\projects\c++\vs\kinect dll\kinect dll\depthreader.h(4):
fatal error C1083: Cannot open include file: 'NuiApi.h': No such file or directory
Note: ConsolApplication1 and Kinect DLL are 2 projects in the same solution, first one have one dependency – Kinect DLL project as DLL. I have “use precompile headers” turned off in both projects!
Kinect DLL projects:
KinectDLL.h:
#ifdef KINECTDLL_EXPORTS
#define KINECTDLL_API __declspec(dllexport)
#else
#define KINECTDLL_API __declspec(dllimport)
#endif
DepthReader.h:
#pragma once
#include <ole2.h>
#include <Windows.h>
#include "NuiApi.h"
#include "KinectDLL.h"
namespace KinectDLL{
class DepthReader{
static KINECTDLL_API const int depthWidth = 640;
static KINECTDLL_API const int depthHeight = 480;
static KINECTDLL_API const int bytesPerPixel = 4;
public:
KINECTDLL_API DepthReader(void);
KINECTDLL_API ~DepthReader(void);
KINECTDLL_API int Run(HINSTANCE hInstance, int nCmdShow);
private:
HANDLE depthStreamHandle;
HANDLE nextDepthFrameEvent;
HANDLE depthStream;
BYTE* depthRGBX;
bool nearMode;
INuiSensor* sensor;
//HWND m_hWnd;
HRESULT CreateFirstConnected();
void Update();
void ProcessDepth();
};
}
DepthReader.cpp
#include "stdafx.h"
#include "DepthReader.h"
namespace KinectDLL{
DepthReader::DepthReader(void) :
nextDepthFrameEvent(INVALID_HANDLE_VALUE),
depthStreamHandle(INVALID_HANDLE_VALUE),
nearMode(false),
sensor(NULL)
{
// create heap storage for depth pixel data in RGBX format
depthRGBX = new BYTE[depthWidth*depthHeight*bytesPerPixel];
}
… and so on, mostly copy and pase from MS Kinect examples...
Consoleapplication1 project:
Consolapplication1.cpp:
#include "KinectDLL.h"
#include "stdafx.h"
#include "Rotations.h"
#include "Camera.h"
#include "FileLoader.h"
#include "DepthReader.h"
using namespace std;
Camera camera;
Rotations rotations;
FileLoader fileLoader;
KinectDLL::DepthReader depthReader;
… then there is OpenGL, points from file. I am using Kinect to contole the scene, not to display data from it. No depthReader for now.
Clearly I am doing something stupid but I can't see what. I am reading Microsoft examples about DLL in VC++ but I can't see what is wrong.
I have just finished created a dll with some functions that depend on the skeleton stream from the kinect. What I did was something like this:
#ifdef KINECTFUNCTIONSDLL_EXPORTS
#define KINECTFUNCTIONSDLL_API __declspec(dllexport)
#else
#define KINECTFUNCTIONSDLL_API __declspec(dllimport)
#endif
#include <Windows.h>
#include <NuiApi.h>
using namespace std;
#include <string>
namespace KinectFunctions{
class GestureRecognizer
{
public:
Vector4 KINECTFUNCTIONSDLL_API resta(Vector4 vector1,Vector4 vector2);
}
}
and now for the .cpp:
#include "KinectFunctionsDLL.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
namespace KinectFunctions{
Vector4 GestureRecognizer::resta(Vector4 vector1,Vector4 vector2){
Vector4 salida;
salida.x=vector1.x-vector2.x;
salida.y=vector1.y-vector2.y;
salida.z=vector1.z-vector2.z;
return salida;
}
}
Keep in mind that the project you use to create the dll must be created checking the DLL option (it's a checkbox that appears when you choose to create a new project. Like it is shown here:
https://www.youtube.com/watch?v=yEqRyQhhto8
And of course you need to add the dependencies for the kinect dll, the kinect10.lib and the headers, like in any project where you want to use the device.