“…已经在* .obj中定义,但是我没有在同一范围内两次定义任何var

问题描述 投票:1回答:1

[我试图进入游戏黑客,并从一个简单的Freecam黑客开始。在清理了一些代码并为某些代码制作了函数和不同文件后,我遇到了一个问题。我总是会收到错误:

我已经搜索了问题,但是没有找到与我的问题相似的东西,其中大多数都具有相同名称的多个定义,但我没有这些,

[我还注释掉了C-。cpp中的全局变量,并在FreeCamFunc.cpp中将我的速度变量命名为不同的名称,但这并没有解决它。

C--.cpp

#include <iostream>
#include <Windows.h>
#include <winuser.h>
#include "FreeCamFunc.cpp"
using namespace std;

extern HANDLE g_program;

int main()
{
    double speed = 0.5;

    DWORD pid = 0x0000452C;
    g_program = OpenProcess(PROCESS_ALL_ACCESS, false, pid);

    LPVOID varAdress = (LPVOID)0x8CAC99E0;

    cout << "Ready" << endl;
    while (true) 
    {
        if (GetKeyState('Q') & 0x8000)
            IncY(varAdress, speed);
        if (GetKeyState('Z') & 0x8000)
            DecY(varAdress, speed);
    }
}

FreeCamFunc.cpp

#include <Windows.h>

HANDLE g_program;

void IncY(LPVOID varAdress, double speedup)
{
    double varValY = 0.0;
    ReadProcessMemory(g_program, varAdress, &varValY, sizeof(varValY), NULL);
    varValY += speedup;
    WriteProcessMemory(g_program, varAdress, (LPCVOID)& varValY, sizeof(varValY), NULL);
}

void DecY(LPVOID varAdress, double speeddown)
{
    double varValY = 0.0;
    ReadProcessMemory(g_program, varAdress, &varValY, sizeof(varValY), NULL);
    varValY -= speeddown;
    WriteProcessMemory(g_program, varAdress, (LPCVOID)& varValY, sizeof(varValY), NULL);
}

我希望一切都很好,因为我只使用了一个全局变量,而其他变量都在作用域中,但错误说明有所不同

"Fehler LNK2005 "void __cdecl DecY(void *,double)" (?DecY@@YAXPAXN@Z) ist bereits in C--.obj definiert. *\C--\FreeCamFunc.obj"
"Fehler LNK2005 "void __cdecl IncY(void *,double)" (?IncY@@YAXPAXN@Z) ist bereits in C--.obj definiert. *\C--\FreeCamFunc.obj"
"Fehler LNK2005 "void * g_program" (?g_program@@3PAXA) ist bereits in C--.obj definiert. *\C--\FreeCamFunc.obj"

saying:...已在c-。obj中定义和

Fehler  LNK1169 Mindestens ein mehrfach definiertes Symbol gefunden.    C-- *\C--.exe

说:找到至少一个重复定义的符号

c++ windows global-variables
1个回答
1
投票

您要包括头文件而不是源文件。您还应该将定义和声明分成适当的cpp和hpp文件。我在这里为您做到了:

main.cpp

#include <iostream>
#include <Windows.h>
#include <winuser.h>
#include "FreeCamFunc.h"
using namespace std;

extern HANDLE g_program;

int main()
{
    double speed = 0.5;

    DWORD pid = 0x0000452C;
    g_program = OpenProcess(PROCESS_ALL_ACCESS, false, pid);

    LPVOID varAdress = (LPVOID)0x8CAC99E0;

    cout << "Ready" << endl;
    while (true) 
    {
        if (GetKeyState('Q') & 0x8000)
            IncY(varAdress, speed);
        if (GetKeyState('Z') & 0x8000)
            DecY(varAdress, speed);
    }
}

FreeCamFunc.h

#pragma once
#include <Windows.h>

void IncY(LPVOID varAdress, double speedup);

void DecY(LPVOID varAdress, double speeddown);

FreeCamFunc.cpp

#include "FreeCamFunc.h"

HANDLE g_program;

void IncY(LPVOID varAdress, double speedup)
{
    double varValY = 0.0;
    ReadProcessMemory(g_program, varAdress, &varValY, sizeof(varValY), NULL);
    varValY += speedup;
    WriteProcessMemory(g_program, varAdress, (LPCVOID)& varValY, sizeof(varValY), NULL);
}

void DecY(LPVOID varAdress, double speeddown)
{
    double varValY = 0.0;
    ReadProcessMemory(g_program, varAdress, &varValY, sizeof(varValY), NULL);
    varValY -= speeddown;
    WriteProcessMemory(g_program, varAdress, (LPCVOID)& varValY, sizeof(varValY), NULL);
}
© www.soinside.com 2019 - 2024. All rights reserved.