#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#if !defined(_WIN32_WINNT)
#define _WIN32_WINNT 0x0501
#endif
extern "C" const IMAGE_DOS_HEADER __ImageBase;
void DumpModule() {
// Get the base address of the running application.
// Can be different from the running module if this code is in a DLL.
HMODULE hModule = GetModuleHandle(NULL);
_tprintf(TEXT("with GetModuleHandle(NULL) = 0x%x\r\n"), hModule);
// Use the pseudo-variable __ImageBase to get
// the address of the current module hModule/hInstance.
_tprintf(TEXT("with __ImageBase = 0x%x\r\n"), (HINSTANCE)&__ImageBase);
// Pass the address of the current method DumpModule
// as parameter to GetModuleHandleEx to get the address
// of the current module hModule/hInstance.
hModule = NULL;
GetModuleHandleEx(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
(PCTSTR)DumpModule,
&hModule);
_tprintf(TEXT("with GetModuleHandleEx = 0x%x\r\n"), hModule);
}
int _tmain(int argc, TCHAR* argv[]) {
DumpModule();
return(0);
}
发现在本机的vs2005环境编译时老是报错
error C2065: 'GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS' : undeclared identifier
加入
d:\vc\console\tmp>cl *.cpp -I "e:\program files\microsoft sdks\windows\v7.1\incl
ude"
后,才通过,
看来
网上说的
#define _WIN32_WINNT 0x0501
及更新SDK都是浮云
不过把代码放到我的VM中去,直接运行vs2008的命令行都是可以直接编译过去的..不解....