0

我正在尝试通过 .bat 文件将这个 main.cpp 文件编译成带有 MinGW 的 DLL。我在 Windows 上,而不是 Linux 顺便说一句。

compile.bat mingw\bin\g++ "srcdll\main.cpp" -O3 -DNDEBUG -s -shared -o "D:\CPP\output\main.dll"

但编译器一直说找不到 XInput.h。我也安装了 DirectX SDK,并且 include 和 lib 目录在我的 PATH 环境变量中。

主文件

#include <windows.h>
#include <XInput.h>

#define EXPORTREAL extern "C" __declspec(dllexport) double __cdecl
#define EXPORTSTRING extern "C" __declspec(dllexport) LPSTR __cdecl

EXPORTREAL setRumble(double index, double left, double right)
{
    XINPUT_VIBRATION vibration;

    vibration.wLeftMotorSpeed = left;
    vibration.wRightMotorSpeed = right;

    XInputSetState(index,&vibration);

    return index;
}

EXPORTREAL leftTrigger(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.bLeftTrigger;
}

EXPORTREAL rightTrigger(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.bRightTrigger;
}

EXPORTREAL leftThumbX(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.sThumbLX;
}

EXPORTREAL leftThumbY(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.sThumbLY;
}

EXPORTREAL rightThumbX(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.sThumbRX;
}

EXPORTREAL rightThumbY(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.sThumbRY;
}

EXPORTREAL getButtonState(double index)
{
    XINPUT_STATE state;

    XInputGetState(index,&state);
    return state.Gamepad.wButtons;
}

EXPORTREAL checkButton(double index, double button)
{
    WORD buttonWord;
    XINPUT_STATE state;

    buttonWord = button;

    XInputGetState(index,&state);
    return (state.Gamepad.wButtons & buttonWord) ? 1 : 0;
}

EXPORTREAL getCtrlState(double index)
{
    XINPUT_STATE state;

    return XInputGetState(index,&state);
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    XINPUT_VIBRATION vibration;

    vibration.wLeftMotorSpeed = 0;
    vibration.wRightMotorSpeed = 0;

    XInputSetState(0,&vibration);

    return TRUE;
}
4

1 回答 1

1
  1. 将标题路径添加到命令行
  2. 错误(未定义的引用)来自链接。您应该在链接行中添加 .a/.o 的路径
于 2012-09-01T23:00:17.653 回答