我该如何制作这个以便所有东西都可以使用它? C++

发布于 2024-08-23 04:09:40 字数 598 浏览 4 评论 0原文

我对 C++ 有点陌生,所以我不知道如何做到这一点,但我重新编码的主要目的是提高程序的速度,我一直在编码一个项目 我的代码是:

HWND hWnd = FindWindow(NULL, L"*window's name*");
DWORD th32ProcId;
HANDLE hProc;

GetWindowThreadProcessId(hWnd, &th32ProcId);

hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, th32ProcId);

所以我有大约 20 个函数,它们在每次运行它们时都使用它们,并且值永远不会改变,所以有什么方法可以声明然后将其设置为它找到的值?

我的代码设置就像这样

一个主文件 int main() ,它只是设置在一个循环上,它不断重新测试并调用其他函数,其他所有内容都在 void name() 中,我有2 int name()

我使用 VC++ 2008。

编辑 不:|我只是想要一种可以与所有程序分享这些价值观的方法。

im somewhat new to c++ so i don't know how to do this but my main point in recoding this is to incress the speed of my program, i have been coding a project
and my code is:

HWND hWnd = FindWindow(NULL, L"*window's name*");
DWORD th32ProcId;
HANDLE hProc;

GetWindowThreadProcessId(hWnd, &th32ProcId);

hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, th32ProcId);

so i have about 20 functions that all use that at the start of each time i run them and the value will never change so is there some way i can declare and then set it at the value of what it finds?

my code is set up like this

one main file int main() and it's just set on a loop and it keeps retesting and calls the other functions and everything else is in a void name() and i have 2 int name()

im using VC++ 2008.

edit
no :| i just want a way i can share thoses values with all of the program.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟到的我 2024-08-30 04:09:40

如果我正确理解你的问题,你想实现某种缓存。那很好,您可以使用 std::map 创建一个缓存。

您可能会遇到类似的情况:

std::map<std::string, HANDLE> cacheMap;

然后您可以检查 cacheMap 以查看结果是否存在。如果它确实存在,您不需要调用该函数,如果它不存在,您将调用该函数并将结果添加到您的地图中。

If I understand your question correctly you want to implement some kind of caching. That would be fine and you can create a cahe with an std::map.

You would probably have something like:

std::map<std::string, HANDLE> cacheMap;

You can then check the cacheMap to see if a result exists. It if does exist you don't need to call the function, if it does not exist you would then call the function and add the result to your map.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文