Scott M
Scott M

Reputation: 395

C++/CLI application for InjectTouchInput API. LNK2028 and LNK2019 errors

I'm trying to build a C++/CLI library in Visual Studio 2012 (on Win8 Release Preview) to use the functions InitializeTouchInjection and InjectTouchInput in C#.

I define my class like so

// 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);
    };
}

and implement the functions

//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;
    }

In stdafx.h I include <windows.h>, which gives the definition of InitializeTouchInjection and InjectTouchInput through <WinUser.h>.

The problem I'm running across is that when I try to build this library, I get the errors LNK2028 and LNK2019 for both functions:

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

I'm not sure what to do. I've tried including /LD in the Configuration Properties >> C/C++ >> Command Line menu. I've tried changing the calling convention to __cdecl in the Advanced menu, but it always reverts back to __stdcall.

Any help on what to do to get around these linker errors?

Upvotes: 1

Views: 1039

Answers (1)

Scott M
Scott M

Reputation: 395

I did not link to the user32.lib file. For those wondering what needed to be done, I used this question as a reference to figure out where to go and what the problem was.

Upvotes: 1

Related Questions