GetModuleHandle() function (API Programming)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JupeMarsInc
    New Member
    • Nov 2006
    • 5

    GetModuleHandle() function (API Programming)

    Hi All,

    I wish you could help me with this one...
    my simple code uses this:
    GetModuleHandle ("E:\\winxp\\sy stem32\\calc.ex e");
    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
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by JupeMarsInc
    Hi All,

    I wish you could help me with this one...
    my simple code uses this:
    GetModuleHandle ("E:\\winxp\\sy stem32\\calc.ex e");
    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\\s ystem32\\calc.e xe", 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?

    Comment

    • JupeMarsInc
      New Member
      • Nov 2006
      • 5

      #3
      Originally posted by sicarie
      It sounds like your path is wrong. Try "C:\\WINDOWS\\s ystem32\\calc.e xe", 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

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        JupeMarsInc-

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

        Comment

        • JupeMarsInc
          New Member
          • Nov 2006
          • 5

          #5
          Originally posted by sicarie
          JupeMarsInc-

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

          no problem :)

          The code:

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


          Code:
          int main()
          {
          	HMODULE GetModH;
          	LPCTSTR FileMod="E:\\WINXP\\system32\\calc.exe";
          	
          	
          	if ((GetModH = GetModuleHandle(FileMod))==NULL)
          		printf("GetModuleHandle failed (%d)\n", GetLastError());
          	
          	return 0;
          }
          and instead of "FileMod" you can just write the string as the argument to the function.

          Thanks.

          Comment

          • JupeMarsInc
            New Member
            • Nov 2006
            • 5

            #6
            anyone ?? :S ..

            Comment

            • sivadhas2006
              New Member
              • Nov 2006
              • 142

              #7
              Can I know why u want to get the module handle of the calc.exe.

              Regards,
              M.Sivadhas.

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                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?

                Comment

                • sushilvanve
                  New Member
                  • Sep 2009
                  • 1

                  #9
                  the help pages for GetModuleHandle

                  To use GetModuleHandle ; the module must have been loaded by the calling process.

                  Comment

                  Working...