我尝试制作使用我的DLL处理Kinect的控制台应用程序。 当我构建我的项目时,我得到:
2> e:\ projects \ c ++ \ vs \ kinect dll \ consoleapplication1 \ consoleapplication1.cpp(4): 警告C4627:'#include“KinectDLL.h”':在查找预编译头时使用跳过 2 - ;将指令添加到'stdafx.h'或重建预编译头 2 - ; e:\michał\ projects \ c ++ \ vs \ kinect dll \ kinect \ tdll \ depthreader.h(4): 致命错误C1083:无法打开包含文件:'NuiApi.h':没有这样的文件或目录
注意:ConsolApplication1和Kinect DLL是同一解决方案中的2个项目,第一个有一个依赖项--Kinect DLL项目作为DLL。我在两个项目中都关闭了“使用预编译头”!
Kinect DLL项目:
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];
}
...依此类推,主要是从MS Kinect示例中复制和使用...
Consoleapplication1项目:
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;
...然后有OpenGL,从文件中指向。我正在使用Kinect来调整场景,而不是显示来自它的数据。目前还没有深度阅读器。
显然我正在做一些愚蠢的,但我看不清楚。我正在阅读有关VC ++中DLL的Microsoft示例,但我看不出有什么问题。
答案 0 :(得分:0)
我刚刚创建了一个带有一些函数的dll,这些函数依赖于来自kinect的骨架流。我做的是这样的:
#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);
}
}
现在是.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;
}
}
请记住,必须创建用于创建dll的项目,检查DLL选项(当您选择创建新项目时,它会出现一个复选框。如下所示: https://www.youtube.com/watch?v=yEqRyQhhto8
当然,你需要为kinect dll,kinect10.lib和标题添加依赖项,就像你想要使用设备的任何项目一样。