473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

GetModuleHandle() function (API Programming)

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
8 27119
sicarie
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
JupeMarsInc-

Sorry, just had to check the basics ;). Can we see the full code?
Nov 8 '06 #4
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
anyone ?? :S ..
Nov 8 '06 #6
sivadhas2006
142 100+
Can I know why u want to get the module handle of the calc.exe.

Regards,
M.Sivadhas.
Nov 9 '06 #7
Banfa
9,065 Expert Mod 8TB
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
To use GetModuleHandle; the module must have been loaded by the calling process.
Sep 7 '09 #9

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

Similar topics

3
by: David Shaw | last post by:
I am studying API programming using C++ and am seeking a away to pass data to a child program opened using CreateProcess. I would appreciate being told whether this is possible and where I can...
3
by: kman3048 | last post by:
Hello, as a relative newcomer to Python API programming I've got a problem: To extend Python: - there is an API C call to create a module - there is also a API C call to create a method -...
3
by: Jason | last post by:
Hi, I am new to windows api programming and I wanted to create a little utility program for myself in c using the mini gw compiler. I bought petzold's book, programming windows 5th edition. I...
0
by: pei_world | last post by:
I am doing a project with Access through a Bluetooth channel, anyone know how to programming with the Bluetooth? or any provided API that I can use? thanks in advance
3
by: Michael C | last post by:
MS API help is still geared towards C programmers only despite that fact that programmers from other languages have been using them for 10+ years now. When looking up an API it can be a real pain...
1
by: James | last post by:
I would like to get a user's first name and last name instead of just their username. According to this link, http://msdn.microsoft.com/library/default.asp?url=/library/en-...
0
by: Nishini | last post by:
I am using "FtpFindFirstFile" function of wininet.dll in my application. I had the Declare statement for this function in my code but when I executed my applicaiton, it gave me an error saying...
2
by: thangviet | last post by:
Hey guys, I have a function which needs to read a file and use the pointer parameter given. the pointer is a structure with five members; int points, float *time, *dhdt, *drate and *diff. The .dat...
5
by: rajatchhibber | last post by:
I am using GetModuleHandle in my function. That function gets called every time I do an operation. I want to know if that function gets called again and again, will the GetModuleHandle cause stack...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.