GetModuleHandle 如何在 Visual c++ 中工作 [英] How does GetModuleHandle work in Visual c++

查看:38
本文介绍了GetModuleHandle 如何在 Visual c++ 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 C++ 新手,即使我知道文件存在,这段代码也总是返回 NULL:

I am new to c++ and this code always returns NULL even though i know the file exists:

HMODULE hModule = GetModuleHandle(TEXT("C:\\Users\\Steve\\Desktop\\stub.exe"));

有趣的是,如果我将 stub.exe 复制到 C:\Windows\system32,它会找到具有以下代码的模块:

Interestingly, if i copy stub.exe to C:\Windows\system32, it finds the module with this code:

HMODULE hModule = GetModuleHandle(TEXT("stub.exe"));

我是否遗漏了一些非常基本的东西?

Am i missing something incredibly basic?

推荐答案

你只能调用 GetModuleHandle(L"C:\\Users\\Steve\\Desktop\\stub.exe"); 当您运行 C:\Users\Steve\Desktop\stub.exe 时.

You can only call GetModuleHandle(L"C:\\Users\\Steve\\Desktop\\stub.exe"); when you're running C:\Users\Steve\Desktop\stub.exe.

但一般来说,您不会为您的 EXE 名称调用 GetModuleHandle.由于每个进程只有一个 EXE,您只需调用 GetModuleHandle(0).

But in general, you don't call GetModuleHandle for your EXE name. Since there's only one EXE per process, you just call GetModuleHandle(0).

这篇关于GetModuleHandle 如何在 Visual c++ 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆