Click here to Skip to main content
15,892,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i want get address by using getprocaddress. but getting error. please tellme how it is possible.
Posted
Comments
[no name] 4-Mar-14 23:56pm    
What type of error? Please give your method to scan.
Member 10017719 4-Mar-14 23:59pm    
Can u explain your method
gupta_abha 5-Mar-14 0:23am    
#include <windows.h>
#include <stdio.h>
#include <string.h>
extern "C" {
__declspec(dllexport) char d[];
}

int main (void) {
char d[]="hello";

HMODULE hMod = GetModuleHandle (NULL);
char *pGlobal = (char*)GetProcAddress (hMod, d);



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

return 0;
output: 0 hello
chandanadhikari 5-Mar-14 7:59am    
what is the error message you are getting?
gupta_abha 5-Mar-14 8:05am    
Iam not getting correct address. i got 0 for address

C++
#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;
}
 
Share this answer
 
Comments
[no name] 5-Mar-14 9:00am    
Neat.
CPallini 5-Mar-14 9:11am    
Thank you.
gupta_abha 5-Mar-14 22:40pm    
@CPallini: thank you . i want more question to you this programmming concept will be work where variable types is not known. if you have idea please tell me how??
wwwx 5-Sep-20 0:33am    
If the code fail, in my case it's due to the DLL path I use is not latest, can check if the dll path is point to newest dll exactly.
wwwx 5-Sep-20 0:33am    
If the code fail, in my case it's due to the DLL path I use is not latest, can check if the dll path is point to newest dll exactly.
hi,
take help from this code example[^]
hope it helps !
 
Share this answer
 
Comments
gupta_abha 5-Mar-14 8:07am    
thanks but what is the mean of typedef int (__cdecl *MYPROC)(LPWSTR). i am not getting
chandanadhikari 5-Mar-14 8:40am    
its a type definition; think you got baffled by complexity of the code ... if you want to know what is typedef then you can check http://www.functionx.com/cpp/keywords/typedef.htm
chandanadhikari 5-Mar-14 8:45am    
please check if solution 2 works for you ... its from CPallini and its easier to understand :)
C++
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/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900