By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,405 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,405 IT Pros & Developers. It's quick & easy.

GetModuleHandle() function (API Programming)

P: 5
Hi All,

I wish you could help me with this one...
my simple code uses this:
GetModuleHandle("E:\\winxp\\system32\\calc.exe");
and the return value of the function is error number 126. which is "module could not be found". and when I try this for example :
GetModuleHandle("kernel32.dll"); IT WORS !!
I do not understand where the problem is ,I have been trying for more than hour :(
Thanks,
JupeMarsInc
Nov 8 '06 #1
Share this Question
Share on Google+
8 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Hi All,

I wish you could help me with this one...
my simple code uses this:
GetModuleHandle("E:\\winxp\\system32\\calc.exe");
and the return value of the function is error number 126. which is "module could not be found". and when I try this for example :
GetModuleHandle("kernel32.dll"); IT WORS !!
I do not understand where the problem is ,I have been trying for more than hour :(
Thanks,
JupeMarsInc
It sounds like your path is wrong. Try "C:\\WINDOWS\\system32\\calc.exe", unless your computer is set up to use the E drive as your hd, and for some reason your WINDOWS folder was renamed to winxp. Did you put that path into Windows Explorer to verify the file is there?
Nov 8 '06 #2

P: 5
It sounds like your path is wrong. Try "C:\\WINDOWS\\system32\\calc.exe", unless your computer is set up to use the E drive as your hd, and for some reason your WINDOWS folder was renamed to winxp. Did you put that path into Windows Explorer to verify the file is there?
Yes ofcourse. the path is valid and the file exists...any other suggestions ?
I'd like to get some help
Nov 8 '06 #3

sicarie
Expert Mod 2.5K+
P: 4,677
JupeMarsInc-

Sorry, just had to check the basics ;). Can we see the full code?
Nov 8 '06 #4

P: 5
JupeMarsInc-

Sorry, just had to check the basics ;). Can we see the full code?

no problem :)

The code:

#include <stdio.h>
#include <windows.h>


Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     HMODULE GetModH;
  4.     LPCTSTR FileMod="E:\\WINXP\\system32\\calc.exe";
  5.  
  6.  
  7.     if ((GetModH = GetModuleHandle(FileMod))==NULL)
  8.         printf("GetModuleHandle failed (%d)\n", GetLastError());
  9.  
  10.     return 0;
  11. }
and instead of "FileMod" you can just write the string as the argument to the function.

Thanks.
Nov 8 '06 #5

P: 5
anyone ?? :S ..
Nov 8 '06 #6

sivadhas2006
100+
P: 142
Can I know why u want to get the module handle of the calc.exe.

Regards,
M.Sivadhas.
Nov 9 '06 #7

Banfa
Expert Mod 5K+
P: 8,916
From the help pages for GetModuleHandle

The GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process.
Kernel32.dll will have been mapped into the address space of the calling process, calc.exe wont.

What are you trying to achieve that made you think you needed the module handle of calc.exe?
Nov 9 '06 #8

P: 1
To use GetModuleHandle; the module must have been loaded by the calling process.
Sep 7 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.