如何使用getprocaddress()查找变量的地址? [英] How to find address of variable using getprocaddress()?

查看:210
本文介绍了如何使用getprocaddress()查找变量的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用getprocaddress获取地址。但得到错误。请告诉我这是怎么可能的。

解决方案

  #include   <   Windows.h  >  
#include < stdio.h >

extern C
{
__ declspec dllexport char d [] = hello world;
}

int main( void
{
HMODULE hMod = GetModuleHandle(NULL);

char * pGlobal =( char *)GetProcAddress(hMod, d);

printf( %s \ n,pGlobal);

return 0 ;
}


hi,

从此代码示例中获取帮助 [ ^ ]

希望它有所帮助!

 printf( %u%s,pGlobal,d); 



如果将该行编译为64位代码,则可能会将64位指针类型切换为32位。所以可能你看到的'0'只是指针的高32位而不是(更有意义的)低32位。



如果你想要使用 printf 打印指针地址,请使用格式说明符%p ,而不是% ü!请参阅 http://www.cplusplus.com/reference/cstdio/printf/ [ ^ ]


Hi, i want get address by using getprocaddress. but getting error. please tellme how it is possible.

解决方案

#include <Windows.h>
#include <stdio.h>

extern "C" 
{
    __declspec(dllexport) char d[] = "hello world";
}

int main (void) 
{
  HMODULE hMod = GetModuleHandle (NULL);

  char *pGlobal = (char*)GetProcAddress (hMod, "d");

  printf("%s\n",pGlobal);

  return 0;
}


hi,
take help from this code example[^]
hope it helps !


printf("%u%s",pGlobal,d);


If you compile that line as 64 bit code, it will likely cut off the 64 bit pointer type to 32 bit. So it may be that the '0' you are seeing is just the upper 32 bits of the pointer rather than the (more meaningful) lower 32 bits.

If you want to print a pointer address using printf, use the format specifier %p, not %u! See http://www.cplusplus.com/reference/cstdio/printf/[^]


这篇关于如何使用getprocaddress()查找变量的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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