1

我正在尝试在 Visual Studio 2012(在 Win8 Release Preview 上)中构建一个 C++/CLI 库,以使用C# 中的InitializeTouchInjectionInjectTouchInput函数。

我这样定义我的班级

// MultiTouchWrapper.h
namespace MultiTouchWrapper {

    public ref class MultiTouchInjection
    {
            public:
            static bool InitializeMultiTouch(int maxCount);
            static bool InjectMultiTouch(int count, float *x, float *y, int *id);
    };
}

并实现功能

//MultiTouchWrapper.cpp

#include "stdafx.h"
#include "MultiTouchWrapper.h"

namespace MultiTouchWrapper{
    bool  MultiTouchInjection::InitializeMultiTouch(int maxCount){
        if(InitializeTouchInjection(maxCount, TOUCH_FEEDBACK_DEFAULT)) return true;
        return false;
    } 
    bool  MultiTouchInjection::InjectMultiTouch(int count, float *x, float *y, int *id){
        POINTER_TOUCH_INFO *contacts = new POINTER_TOUCH_INFO[count];
        for(int i=0; i<count; i++){
            contacts[i].pointerInfo.pointerType = PT_TOUCH;
            contacts[i].pointerInfo.pointerId = id[0];
            contacts[i].pointerInfo.ptPixelLocation.y = (LONG)y[0];
            contacts[i].pointerInfo.ptPixelLocation.x = (LONG)x[0];
            contacts[i].touchFlags = TOUCH_FLAG_NONE;
            contacts[i].touchMask = TOUCH_MASK_NONE;

        }
        if(InjectTouchInput(count, contacts)) return true; //defined like this to avoid a warning about BOOL vs bool.
        return false;
    }

在 stdafx.h 我包括<windows.h>,它给出了InitializeTouchInjectionInjectTouchInputthrough的定义<WinUser.h>

我遇到的问题是,当我尝试构建这个库时,两个函数都出现错误 LNK2028 和 LNK2019:

Error   1   error LNK2028: unresolved token (0A00003B) "extern "C" int __stdcall InjectTouchInput(unsigned int,struct tagPOINTER_TOUCH_INFO const *)" (?InjectTouchInput@@$$J18YGHIPBUtagPOINTER_TOUCH_INFO@@@Z) referenced in function "public: static bool __clrcall MultiTouchWrapper::MultiTouchInjection::InjectMultiTouch(int,float *,float *,int *)" (?InjectMultiTouch@MultiTouchInjection@MultiTouchWrapper@@$$FSM_NHPAM0PAH@Z)    C:\Users\mediascape\documents\visual studio 2012\Projects\MultiTouchWrapper\MultiTouchWrapper\MultiTouchWrapper.obj MultiTouchWrapper
Error   2   error LNK2028: unresolved token (0A000063) "extern "C" int __stdcall InitializeTouchInjection(unsigned int,unsigned long)" (?InitializeTouchInjection@@$$J18YGHIK@Z) referenced in function "public: static bool __clrcall MultiTouchWrapper::MultiTouchInjection::InitializeMultiTouch(int)" (?InitializeMultiTouch@MultiTouchInjection@MultiTouchWrapper@@$$FSM_NH@Z) C:\Users\mediascape\documents\visual studio 2012\Projects\MultiTouchWrapper\MultiTouchWrapper\MultiTouchWrapper.obj MultiTouchWrapper
Error   3   error LNK2019: unresolved external symbol "extern "C" int __stdcall InitializeTouchInjection(unsigned int,unsigned long)" (?InitializeTouchInjection@@$$J18YGHIK@Z) referenced in function "public: static bool __clrcall MultiTouchWrapper::MultiTouchInjection::InitializeMultiTouch(int)" (?InitializeMultiTouch@MultiTouchInjection@MultiTouchWrapper@@$$FSM_NH@Z)  C:\Users\mediascape\documents\visual studio 2012\Projects\MultiTouchWrapper\MultiTouchWrapper\MultiTouchWrapper.obj MultiTouchWrapper
Error   4   error LNK2019: unresolved external symbol "extern "C" int __stdcall InjectTouchInput(unsigned int,struct tagPOINTER_TOUCH_INFO const *)" (?InjectTouchInput@@$$J18YGHIPBUtagPOINTER_TOUCH_INFO@@@Z) referenced in function "public: static bool __clrcall MultiTouchWrapper::MultiTouchInjection::InjectMultiTouch(int,float *,float *,int *)" (?InjectMultiTouch@MultiTouchInjection@MultiTouchWrapper@@$$FSM_NHPAM0PAH@Z) C:\Users\mediascape\documents\visual studio 2012\Projects\MultiTouchWrapper\MultiTouchWrapper\MultiTouchWrapper.obj MultiTouchWrapper

我不知道该怎么办。我尝试在配置属性 >> C/C++ >> 命令行菜单中包含 /LD。我尝试__cdecl在高级菜单中将调用约定更改为,但它总是恢复为__stdcall.

有关如何解决这些链接器错误的任何帮助?

4

1 回答 1

1

我没有链接到 user32.lib 文件。对于那些想知道需要做什么的人,我用这个问题作为参考来弄清楚去哪里以及问题是什么。

于 2012-08-29T14:15:26.920 回答