gpt4 book ai didi

c++ - 正确使用头文件

转载 作者:行者123 更新时间:2023-11-27 22:34:46 24 4
gpt4 key购买 nike

我正在尝试扩展我的 C++ 游戏黑客技能,因为当我开始时(2 年前)我做了一个错误的决定:继续使用 vb.net 进行游戏黑客而不是学习 c++(因为我有一些 vb.net其他语言的知识和 0 知识)

因此,现在作为我必须创建我的工具包的第一步,我将在其中使用我自己的模板:

  • Nathalib.h(我的模板,包含游戏黑客的所有常用功能)。
#pragma once
#include <iostream>
#include <Windows.h>
#include <string>

#include <TlHelp32.h>
#include <stdio.h>

using namespace std;

DWORD ProcessID;

int FindProcessByName(string name)
{
HWND hwnd = FindWindowA(0, name);
GetWindowThreadProcessId(hwnd, &ProcessID);

if (hwnd)
{
return ProcessID;
}
else
{
return 0;
}
}
  • Hack.cpp(显然是作弊,每个游戏都会不同)。
#pragma once
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <string>
#include <Nathalib.h>
using namespace std;

int main()
{
While(True)
{
cout << FindProcessByName("Calculator") << endl;
getchar();
cout << "-----------------------------------" << endl << endl;
}
return 0;
}
  • Target.cpp(因为我们不是坏 child ,所以我必须提供我自己的目标)。
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
#define CHAR_ARRAY_SIZE 128

int main()
{
int varInt = 123456;
string varString = "DefaultString";
char arrChar[CHAR_ARRAY_SIZE] = "Long char array right there ->";
int * ptr2int;
ptr2int = &varInt;
int ** ptr2ptr;
ptr2ptr = &ptr2int;
int *** ptr2ptr2;
ptr2ptr2 = &ptr2ptr;

while(True) {
cout << "Process ID: " << GetCurrentProcessId() << endl;

cout << "varInt (0x" << &varInt << ") = " << varInt << endl;
cout << "varString (0x" << &varString << ") = " << varString << endl;
cout << "varChar (0x" << &arrChar << ") = " << arrChar << endl;

cout << "ptr2int (0x" << hex << &ptr2int << ") = " << ptr2int << endl;
cout << "ptr2ptr (0x" << hex << &ptr2ptr << ") = " << ptr2ptr << endl;
cout << "ptr2ptr2 (0x" << hex << &ptr2ptr2 << ") = " << ptr2ptr2 << endl;

cout << "Press ENTER to print again." << endl;
getchar();
cout << "-----------------------------------" << endl << endl;
}

return 0;
}

不知道为什么头文件不被识别。

  1. 这是包含头文件的正确方法吗?我应该创建一个命名空间/类/对象来调用它吗?
  2. 这是创建头文件的正确方法吗?或者我应该为此目的创建另一种项目/资源?
  3. 我应该如何调用我的库方法?喜欢 LibraryName.MethodName?

我只是来自其他语言,一些想法/功能在其他语言中不可用(这就是我对这个感兴趣的原因)

如果有什么忘记补充的,请告诉我,我会更新

谢谢

最佳答案

有多个错误 - 请检查您的教科书。

  1. 您在 #include "" 中包含自己的 header .系统 header 包含在 #include<>
  2. 头文件通常包含函数声明。函数体进入对应的.cpp文件。
  3. 您可以通过名称调用您的库函数。如果它们在命名空间中,则可能意味着格式为 namespacename::functionname(arguments) .

关于c++ - 正确使用头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56185529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com