任何想法如何解决LNK2019 - 未解决的外部符号,错误?

时间:2017-01-23 16:45:42

标签: c++ visual-studio

我有这个恼人的错误,并且不知道如何解决问题;我使用的是Visual Studio 2015社区版。

我正在创建一个附加到GTA5.exe的C / C ++控制台应用程序,并使用地址修改健康状况。

这是错误:

Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) GTAConsole

以下是截图: http://prntscr.com/dzbpsa.png

GTAConsole.cpp代码:

#include "stdafx.h" // Precompiled header

#include <Windows.h> // Allows window editing; setting text, etc
#include <iostream>
#include <TlHelp32.h>
#include <conio.h>

using namespace std; // Allows use of std::

__int64 GetModuleBaseAddress(LPCWSTR szProcessName, LPCWSTR szModuleName)
{
    HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe32;

if (hSnap == INVALID_HANDLE_VALUE)
{
    return 0;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnap, &pe32) == 0)
{
    CloseHandle(hSnap);
    return 0;
}

do
{
    if (lstrcmp(pe32.szExeFile, szProcessName) == 0)
    {
        int PID;
        PID = pe32.th32ProcessID;

        HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
        MODULEENTRY32 xModule;

        if (hSnap == INVALID_HANDLE_VALUE)
        {
            return 0;
        }
        xModule.dwSize = sizeof(MODULEENTRY32);
        if (Module32First(hSnap, &xModule) == 0)
        {
            CloseHandle(hSnap);
            return 0;
        }

        do
        {
            if (lstrcmp(xModule.szModule, szModuleName) == 0)
            {
                CloseHandle(hSnap);
                return (__int64)xModule.modBaseAddr;
            }
        } while (Module32Next(hSnap, &xModule));
        CloseHandle(hSnap);
        return 0;
    }
} while (Process32Next(hSnap, &pe32));
CloseHandle(hSnap);
return 0;
}

int Main()
{

wchar_t* WindowName = (L"Grand Theft Auto V");
wchar_t* GameTitle = (L"GTA5.exe");

HWND WindowHandle = FindWindow(NULL, WindowName);
__int64 BaseAddress = GetModuleBaseAddress(GameTitle, GameTitle);

DWORD ProcessID;
GetWindowThreadProcessId(WindowHandle, &ProcessID);

HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, ProcessID);

std::cout << "[sucess]: GTAV.exe has been found!" << std::endl;

for (;;)
{
    if (GetAsyncKeyState(VK_NUMPAD1))
    {
        Sleep(250);

        float Health = 200;
        __int64 pPlayerInformationAddress = 0;

        DWORD SocialClubPlayerInformation = 0x01ED6D88;
        DWORD HealthOffset = 0x280;

        ReadProcessMemory(pHandle, (void*)(BaseAddress +      SocialClubPlayerInformation), &pPlayerInformationAddress, sizeof(pPlayerInformationAddress), NULL);
        ReadProcessMemory(pHandle, (void*)(pPlayerInformationAddress + HealthOffset), &Health, sizeof(Health), NULL);

        std::cout << Health << std::endl;
    }
}

Sleep(1);
}

如果有人可以提供帮助,那就太棒了!

1 个答案:

答案 0 :(得分:2)

更改行Main()main()