Loadlibrary (Ex) fails, getlasterror returns 127 (the specified program cannot be found)

Source: Internet
Author: User
A strange problem encountered when debugging a program: a very simple Win32 DLL is a dllmain, which contains several lines of code that call the API function at process attach to obtain the specified key value of the registry, which is very simple. But something went wrong. The problem is still weird: when another program loadlibrary loads this DLL, null is returned, and getlasterror returns 127 ("the specified program cannot be found "). Haha, this error is strange and difficult to understand (in fact, I have not understood it as "specifying a program "). Remove the lines of code in dllmain, leave only empty functions, and then compile the function. With those lines of API, loadlibrary cannot be added.

In theory, even if the API call fails, shouldn't the DLL loading be affected ?? When a DLL fails to be loaded, the result of dllmain is false, or the DLL structure is incorrect. These two points should not exist in my program: My dllmain explicitly returns true (in fact, DLL is not loaded, and dllmain is not executed ), this dll was just compiled by vs2005, and its structure is unlikely to be damaged.

Later, we used the exclusion method to determine that the reggetvalue was called.

Check out msdn. This function "requires Windows Vista or Windows XP Professional x64 Edition" is a problem. I use a 32-bit version of Windows XP Pro. But it is hard to understand. Even if I call an unsupported API function, the execution of this function throws at most (or returns false or the like ), however, I encountered a problem before the function was executed. It seems that the compiler did something during DLL compilation due to the use of this function !! I cannot understand it. The lasterror information after loadlibrary failure is even more misleading!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.