Джава ошибка 126

What is Error 126?

Error 126 is a kind of Runtime error that is found in the Microsoft Windows operating systems. The file can be found for Java. Java Error Code 126 has a popularity rating of 1 / 10.

Errors

This tutorial contains information on Error 126 or otherwise known as Java Error Code 126. Errors such as Java Error Code 126 indicate your machine has faulty hardware or software that should be fixed when possible. Below is information on how to repair Error 126 and get your computer back to normal.

Megaphone Signs of Error 126:

  • When your computer freezes or locks up at random.
  • When your computer crashes when you are running Java.
  • If Java Error Code 126 pops up and causes a program to shutdown or your computer to crash.
  • Your computer is running slow, taking a long time to boot up, and you suspect Error 126 by Java is the cause.

What Causes Runtime Errors Like Error 126?

There are several causes of runtime errors like Java Error Code 126, such as viruses, out of date drivers, missing files or folders, incomplete or poor installation, and registry errors. They can also occur due to an issue with the computer’s memory, which may often be due to a hardware problem. In some cases there was an issue installing Java and an error occurred.

Fix How to Fix Java Error Code 126

Follow the step by step instructions below to fix the Error 126 problem. We recommend you do each in order. If you wish to skip these steps because they are too time consuming or you are not a computer expert, see our easier solution below.

Step 1 — Uninstall and Reinstall Java

If the Java Error Code 126 is a result of using Java, you may want to try reinstalling it and see if the problem is fixed. Please follow these steps:

Windows XP

  1. Click “Start Menu”.
  2. Click “Control Panel”.
  3. Select the “Add or Remove” program icon.
  4. Find the Error 126 associated program.
  5. Click the Change/Remove button on the right side.
  6. The uninstaller pop up will give you instructions. Click “okay” or “next”  or “yes” until it is complete.
  7. Reinstall the software.

Windows 7 and Windows Vista

  1. Click “Start Menu”.
  2. Click “Control Panel”.
  3. Click “Uninstall a Program” which is under the “Programs” header.
  4. Find the Error 126 associated program.
  5. Right click on it and select “Uninstall”.
  6. The uninstaller pop up will give you instructions. Click “okay” or “next”  or “yes” until it is complete.
  7. Reinstall the software and run the program.

Windows 8, 8.1, and 10

  1. Click “Start Menu”.
  2. Click “Programs and Features”.
  3. Find the software that is linked to **insert file name**.
  4. Click Uninstall/Change.
  5. The uninstaller will pop up and give you instructions. Click “okay” and “next” until it is complete.
  6. Restart your computer.
  7. Reinstall the software and run the program.

Step 2 — Remove Registry Entry related to Error 126

Warning WARNING: Do NOT edit the Windows Registry unless you absolutely know what you are doing. You may end up causing more trouble than you start with. Proceed at your OWN RISK.

  1. Create a backup of registry files.
  2. Click “Start”.
  3. Type regedit, select it, and grant permission in order to proceed.
  4. Click HKEY LOCAL MACHINE>>SOFTWARE>>Microsoft>>Windows>>Current Version>>Uninstall.
  5. Find the Java Error Code 126 software from the list you wish to uninstall.
  6. Select the software and double click the UninstallString icon on the right side.
  7. Copy the highlighted text.
  8. Exit and go to the search field.
  9. Paste the data.
  10. Select Okay in order to uninstall the program.
  11. Reinstall the software.

Step 3 – Ensure Junk Isn’t Causing Java Error Code 126

Any space that isn’t regularly cleaned out tends to accumulate junk. Your personal computer is no exception. Constant web browsing, installation of applications, and even browser thumbnail caches slow down your device and in the absence of adequate memory, can also trigger a Java Error Code 126 error.

So how do you get around this problem?

  • You can either use the Disk Cleanup Tool that comes baked into your Windows operating system.
  • Or you can use a more specialized hard drive clean up solution that does a thorough job and flushes the most stubborn temporary files from your system.

Both solutions may take several minutes to complete the processing of your system data if you haven’t conducted a clean up in a while.
The browser caches are almost a lost cause because they tend to fill up quite rapidly, thanks to our constantly connected and on the go lifestyle.
Here’s how you can run the Window’s Disk Cleanup Tool, without performance issues or surprises.

  • For Windows XP and Windows 7, the program can be ran from “Start” and from the “Command Prompt”.
    • Click “Start”, go to All Programs > Accessories > System Tools, click Disk Cleanup. Next choose the type of files you wish to remove, click OK, followed by “Delete Files”.
    • Open up the Command Prompt, type “c:windowscleanmgr.exe /d” for XP and “cleanmgr” for Windows 7. Finish by pressing “Enter”.
  • For Windows 8 and Windows 8.1, the Disk Cleanup Tool can be accessed directly from “Settings”. Click “Control Panel” and then “Administrative Tools”. You can select the drive that you want to run the clean up on. Select the files you want to get rid of and then click “OK” and “Delete Files”.
  • For Windows 10, the process is simplified further. Type Disk Cleanup directly in the search bar and press “Enter”. Choose the drive and then the files that you wish to wipe. Click “OK”, followed by “Delete Files”.

The progressive ease with which the Cleanup Tool can be used points to the growing importance of regularly deleting temporary files and its place in preventing Java Error Code 126.

Warning PRO TIP:
Remember to run the Disk Cleanup as an administrator.


Step 4 – Fix Infections and Eliminate Malware in Your PC

How do you gauge if your system is infected with a malware and virus?

Well, for one, you may find certain applications misbehaving.

And you may also see the occurrence of Error 126.

Infections and malware are the result of:

  • Browsing the Internet using open or unencrypted public Wi-Fi connections
  • Downloading applications from unknown and untrustworthy sources
  • Intentional planting of viruses in your home and office networks

But thankfully, their impact can be contained.

  • Enter “safe mode” by pressing the F8 key repeatedly when your device is restarting. Choose “Safe Mode with Networking” from the Advanced Boot Options menu.
  • Back up all the data in your device to a secure location. This is preferably a storage unit that is not connected to your existing network.
  • Leave program files as is. They are where the infection generally spreads from and may have been compromised.
  • Run a thorough full-system scan or check of an on-demand scanner. If you already have an antivirus or anti-malware program installed, let it do the heavy lifting.
  • Restart your computer once the process has run its course.
  • Lastly, change all your passwords and update your drivers and operating system.

Warning PRO TIP: Are you annoyed by the frequent updates to your antivirus program? Don’t be! These regular updates add new virus signatures to your software database for exponentially better protection.


Step 5 – Return to the Past to Eliminate Error 126

The steps outlined up until this point in the tutorial should have fixed Java Error Code 126 error. But the process of tracking what has caused an error is a series of educated guesses. So in case the situation persists, move to Step 5.

Windows devices give users the ability to travel back in time and restore system settings to an uncorrupted, error free state.
This can be done through the convenient “System Restore” program. The best part of the process is the fact that using System Restore doesn’t affect your personal data. There is no need to take backups of new songs and pictures in your hard drive.

  • Open “Control Panel” and click on “System & Security”.
  • Choose the option “System”.
  • To the left of the modal, click on “System Protection”.
  • The System Properties window should pop-up. You’ll be able to see the option “System Restore”. Click on it.
  • Go with “Recommended restore” for the path of least hassles and surprises.
  • Choose a system restore point (by date) that will guarantee taking your device back to the time when Error 126 hasn’t been triggered yet.
  • Tap “Next” and wrap up by clicking “Finish”.

If you’re using Windows 7 OS, you can reach “System Restore” by following the path Start > All Programs > Accessories > System Tools.


Step 6 — Error 126 Caused by Outdated Drivers

Updating a driver is not as common as updating your operating system or an application used to run front-end interface tasks.

Drivers are software snippets in charge of the different hardware units that keep your device functional.

So when you detect an Java Error Code 126 error, updating your drivers may be a good bet. But it is time consuming and shouldn’t be viewed as a quick fix.

Here’s the step-by-step process you can go through to update drivers for Windows 8, Windows 8.1 and Windows 10.

  • Check the site of your hardware maker for the latest versions of all the drivers you need. Download and extract them. We strongly advice going with original drivers. In most cases, they are available for free on the vendor website. Installing an incompatible driver causes more problems than it can ever fix.
  • Open “Device Manager” from the Control Panel.
  • Go through the various hardware component groupings and choose the ones you would like to update.
  • On Windows 10 and Windows 8, right-click on the icon of the hardware you would like to update and click “Update Driver”.
  • On Windows 7 and Vista, you right-click the hardware icon, choose “Properties”, navigate to the Driver panel, and then click “Update Driver”.
  • Next you can let your device automatically search for the most compatible drivers, or you can choose to update the drivers from the versions you have on your hard drive. If you have an installer disk, then the latter should be your preferred course of action. The former may often get the driver selection incorrect.
  • You may need to navigate a host of warnings from the Windows OS as you finalize the driver update. These include “Windows can’t verify that the driver is compatible” and “Windows can’t verify the publisher of this driver”. If you know that you have the right one in line, click “Yes”.
  • Restart the system and hopefully the Java Error Code 126 error should have been fixed.

Step 7 – Call the Windows System File Checker into Action

By now the Java Error Code 126 plaguing your device should have been fixed. But if you haven’t resolved the issue yet, you can explore the Windows File Checker option.

With the Windows File Checker, you can audit all the system files your device needs to operate, locate missing ones, and restore them.
Sound familiar? It is almost like “System Restore”, but not quite. The System Restore essentially takes you back in time to a supposedly perfect set up of system files. The File Checker is more exhaustive.

It identifies what is amiss and fills the gaps.

  • First and foremost, open up an elevated command prompt.
  • Next, if you are using Windows 8, 8.1 or 10, enter “DISM.exe /Online /Cleanup-image /Restorehealth” into the window and press Enter.
  • The process of running the Deployment Image Servicing and Management (DISM) tool may take several minutes.
  • Once it completes, type the following command into the prompt “sfc /scannow”.
  • Your device will now go through all protected files and if it detects an anomaly, it will replace the compromised version with a cached version that resides at %WinDir%System32dllcache.

Step 8 – Is your RAM Corrupted? Find Out.

Is it possible? Can the memory sticks of your device trigger Error 126?

It is unlikely – because the RAM chips have no moving parts and consume little power. But at this stage, if all else has failed, diagnosing your RAM may be a good move.

You can use the Windows Memory Diagnostics Tool to get the job done. Users who are on a Linux or Mac and are experiencing crashes can use memtest86.

  • Open up your device and go straight to the “Control Panel”.
  • Click on “Administrative Tools”.
  • Choose “Windows Memory Diagnostic”.
  • What this built-in option does is it burns an ISO image of your RAM and boots the computer from this image.
  • The process takes a while to complete. Once it is done, the “Status” field at the bottom of the screen populates with the result of the diagnosis. If there are no issues with your RAM/memory, you’ll see “No problems have been detected”.

One drawback of the Windows Memory Diagnostic tool pertains to the number of passes it runs and the RAM segments it checks.

Memtest86 methodically goes over all the segments of your memory – irrespective of whether it is occupied or not.

But the Windows alternative only checks the occupied memory segments and may be ineffective in gauging the cause of the Java Error Code 126 error.


Step 9 – Is your Hard Drive Corrupted? Find Out.

Your RAM or working memory isn’t the only culprit that may precipitate an Java Error Code 126 error. The hard drive of your device also warrants close inspection.

The symptoms of hard drive error and corruption span:

  • Frequent crashes and the Blue Screen of Death (BSoD).
  • Performance issues like excessively slow responses.
  • Errors like Error 126.

Hard drives are definitely robust, but they don’t last forever.

There are three things that you can do to diagnose the health of your permanent memory.

  • It is possible that your device may have a hard time reading your drive. This can be the cause of an Java Error Code 126 error. You should eliminate this possibility by connecting your drive to another device and checking for the recurrence of the issue. If nothing happens, your drive health is okay.
  • Collect S.M.A.R.T data by using the WMIC (Windows Management Instrumentation Command-line) in the command prompt. To do this, simply type “wmic” into the command prompt and press Enter. Next follow it up with “diskdrive get status”. The S.M.A.R.T status reading is a reliable indicator of the longevity of your drive.
  • Fix what’s corrupt. Let’s assume you do find that all isn’t well with your hard drive. Before you invest in an expensive replacement, using Check Disk or chkdsk is worth a shot.
    • Open the command prompt. Make sure you are in Admin mode.
    • Type “chkdsk C: /F /X /R” and press “Enter”. “C” here is the drive letter and “R” recovers data, if possible, from the bad sectors.
    • Allow the system to restart if the prompt shows up.
    • And you should be done.

These steps can lead to the resolution you’re seeking. Otherwise the Java Error Code 126 may appear again. If it does, move to Step 10.


Step 10 – Update Windows OS

Like the software applications you use to render specific tasks on your device, the Operating System also requires periodic updates.
Yes, we’ve all heard the troubling stories.

Devices often develop problems post unfinished updates that do not go through. But these OS updates include important security patches. Not having them applied to your system leaves it vulnerable to viruses and malware.

And may also trigger Error 126.

So here’s how Windows 7, Windows 8, Windows 8.1 and Windows 10 users can check for the latest updates and push them through:

  • Click the “Start” button on the lower left-hand corner of your device.
  • Type “Updates” in the search bar. There should be a “Windows Update” or “Check for Updates” option, based on the OS version you’re using.
  • Click it. The system will let you know if any updates are available.
  • You have the convenience of choosing the components of the update you’d like to push through. Always prioritize the security updates.
  • Click “OK” followed by “Install Updates”.

Step 11 – Refresh the OS to Eliminate Persistent Java Error Code 126 Error

“Windows Refresh” is a lifesaver.

For those of you who are still with us and nothing has worked to eliminate the Error 126, until recently, a fresh install of Windows would have been the only option.

Not anymore.

The Windows Refresh is similar to reinstalling your Windows OS, but without touching your personal data. That’s hours of backup time saved in a jiffy.

Through the Refresh, all your system files become good as new. The only minor annoyance is the fact that any custom apps you’ve installed are gone and the system applications you had uninstalled are back.

Still, it is the best bet as the final step of this process.

  • Enter the “Settings” of your PC and click on “Change Settings”.
  • Click “Update and recovery” and then choose “Recovery”.
  • Select “Keep my files”. This removes apps and settings, but lets your personal files live on.
  • You’ll get some warning messages about the apps that will be uninstalled. If you’ve gone through a recent OS upgrade, the Refresh process makes it so that you can’t go back to your previous OS version – if you should ever feel the need to do it.
  • Click the “Refresh” button.

Are you using an older version of Windows that doesn’t come with the power to “Refresh”?

Maybe it is time to start from scratch.

  • Enter your BIOS set-up.
  • This is where you need to change your computer’s boot order. Make it so that the boot happens not from the existing system files, but from the CD/DVD Drive.
  • Place the original Windows disk in the CD/DVD drive.
  • Turn on or restart the device.
  • Choose where you’d like the system files to be installed.
  • Your PC will restart several times as the process runs its course.


FAQ’s

Do Runtime Errors Like Error 126 Cause My Computer to Freeze Up?

A runtime error basically refers to an error that affects a running program. The error may cause a program to freeze, crash, or hang. Sometimes they can cause the entire computer to freeze up on you. They are one of the top causes of a computer freezing up.

Do I Need to Reinstall Windows Because of Runtime Errors?

Usually no. The errors can typically be fixed by diagnosing and solving the problem yourself or using a specialized software to do the work for you. When these fails, however, reinstalling may be an option to try as a last resort. Make sure you follow the instructions and properly backup all data before doing so.

How Long Will It Take to Fix Runtime Errors like Java Error Code 126?

Depending on the problem, it may take anywhere from five minutes to fifty minutes. The most time consuming process is finding what’s causing the problem, it may be a hardware issue or a software glitch. Once the issue has been correctly identified, it only takes a few minutes to solve the problem. Using a software can help you save time since it works in a specifically designed way solving the problem in a quick manner.

Green Arrow

Start Download Now

Author:

Curtis Hansen

Curtis Hansen has been using, fiddling with, and repairing computers ever since he was a little kid. He contributes to this website to help others solve their computer issues without having to buy a new one.

Netbeans crashes after a while with error:

Loadlibrary failed with error 126: the specified module could not be found

I tried uninstalling and reinstalling netbeans and java. I also tried few solutions posted earlier for this error, but its still not working.

I am using Windows 7 Professional 64-bit Operating System.

Any help will be appreciated.

Thanks.

asked Sep 26, 2014 at 19:06

Vikram Parikh's user avatar

3

I tried the previous answer as well but it didn’t work. I think the above was pretty much right but what worked for me was that I had to uninstall my AMD driver and reinstall it for this to resolve. It must have been a bad dll or something.

  1. right click start
  2. select device manager
  3. from display adapter
  4. right click AMD Radeon(TM) graphics
  5. select uninstall
  6. make sure Delete the driver software for this device
  7. click uninstall

uninstalled driver then either wait or restart for it to download the new driver. not really an elegant solution but it worked for me.

answered Jun 19, 2021 at 22:06

Adam's user avatar

AdamAdam

133 bronze badges

Probably a missing dll or broken uninstall from AMD drivers. Try this:

  1. Run CMD as administrator
  2. type: cd /d C:/Windows/System32
  3. for 32bit type: copy atioglxx.dll .dll
  4. for 64bit type: copy atio6axx.dll .dll

If you are running Windows 7 you might need this code for 64bit systems

copy atio6axx.dll atiogl64.dll

Also you could use CCleaner or similar to remove all traces of AMD drivers and reinstall your video drivers.

answered Mar 24, 2015 at 18:37

zanteszuken's user avatar

1

@zackmartin

I am using Windows 7SP1 64bit (but 32-bit JVM). I was trying to use ntservice from the contrib directory, but couldn’t get it to work. So I modified it slightly — added «throw LastErrorException» to all the API calls, and added some code to open a logfile and redirect stderr/stdout to it (since otherwise you can’t get the output of the service). And I discovered that RegisterServiceCtrlHandlerEx fails with error 126 (The specified module could not be found). Investigating further, I believe what is happening is as follows:

  1. RegisterServiceCtrlHandlerExW calls GetModuleHandleExW on the function pointer passed in
    — I guess, for some unknown reason, it wants to know what DLL/EXE the pointer belongs to
  2. With a normal service, this will return the module handle for some DLL or EXE
  3. But with a JNA callback, this points to a memory buffer VirtualAlloc-allocated by FFI
  4. So GetModuleHandleExW fails with 126 and RegisterServiceCtrlHandlerExW as a whole fails

Solution: It is a hard one. I guess the only way forward would be to modify FFI to write out the trampoline code to a DLL in a temporary directory, and then load that into memory. From reading the FFI code, it looks like it actually does this on some other platforms, but not windows. Obviously you would not want it to do this for every callback, but only for ones like this where the VirtualAlloc issue is a problem. But making modifications to the FFI code like this is a bit beyond me — maybe someone else will feel sufficiently inclined?

Since it looks like others have got this working before, maybe RegisterServiceCtrlHandlerExW calling GetModuleHandleExW is new code in some new versions of Windows.

@zackmartin

BTW, I found the call to GetModuleHandleExW was falling using rohitab API Monitor.

@zackmartin

I was thinking more about this, I was thinking a possible workaround might be to build a custom DLL with just two exports, one a global variable and the other a function. The function just does an indirect jump using the contents of the global variable. Then LoadLibrary the DLL, GetProcAddress the variable and stick the address of the native code of the JNA callback in there, then GetProcAddress the function and pass it to RegisterServiceCtrlHandlerExW. Hopefully then GetModuleHandleExW will work fine, since it will return the module handle for the custom DLL. In the process of trying this, I will let you know if it works or not.

@twall

Is this specific to windows 7?

On Mar 16, 2012, at 8:19 PM, zackmartin wrote:

I am using Windows 7SP1 64bit (but 32-bit JVM). I was trying to use ntservice from the contrib directory, but couldn’t get it to work. So I modified it slightly — added «throw LastErrorException» to all the API calls, and added some code to open a logfile and redirect stderr/stdout to it (since otherwise you can’t get the output of the service). And I discovered that RegisterServiceCtrlHandlerEx fails with error 126 (The specified module could not be found). Investigating further, I believe what is happening is as follows:

  1. RegisterServiceCtrlHandlerExW calls GetModuleHandleExW on the function pointer passed in
    — I guess, for some unknown reason, it wants to know what DLL/EXE the pointer belongs to
  2. With a normal service, this will return the module handle for some DLL or EXE

Normally most JNA-mapped functions requiring a module handle just use null when calling the function, which does the right thing. How did you determine GetModuleHandleExW was being called?

Are you certain that all required DLLs (including jnidispatch.dll) are available on PATH when the service is started? If not, you’d get the «module not found» error.

  1. But with a JNA callback, this points to a memory buffer VirtualAlloc-allocated by FFI
  2. So GetModuleHandleExW fails with 126 and RegisterServiceCtrlHandlerExW as a whole fails

I’m not certain the cause is what you think it is. Fundamentally, the ntservice bits register the JVM executable as the service entry point, and set up command-line arguments to configure it.

Solution: It is a hard one. I guess the only way forward would be to modify FFI to write out the trampoline code to a DLL in a temporary directory, and then load that into memory. From reading the FFI code, it looks like it actually does this on some other platforms, but not windows. Obviously you would not want it to do this for every callback, but only for ones like this where the VirtualAlloc issue is a problem. But making modifications to the FFI code like this is a bit beyond me — maybe someone else will feel sufficiently inclined?

Since it looks like others have got this working before, maybe RegisterServiceCtrlHandlerExW calling GetModuleHandleExW is need code in some new versions of Windows.

Might be specific to win7.


Reply to this email directly or view it on GitHub:
#62

@zackmartin

Hello twall, I believe it probably is specific to Windows7. I am going to test things on WinXP soon, I am guessing on WinXP none of this will be necessary. I determined it was error 126 in three ways:

  1. my declaration of RegisterServiceCtrlHandlerExW had «throw LastErrorException» on it, and that threw error 126
  2. I used rohitab API monitor (http://www.rohitab.com/apimonitor) and I saw that RegisterServiceCtrlHandlerExW was
    calling GetModuleHandleExW which was failing with 126
  3. I disassembled advapi32.dll, and by tracing things around I found that it does indeed end up calling GetModuleHandleExW for some reason

I am not sure WHY it would be calling GetModuleHandleExW. maybe it is related to some kind of internal diagnostics??? I can’t pass null as the module handle, since I’m not calling it, Microsoft’s own code is

I know I’m not missing «jnidispatch.dll», etc., since other Win32 API calls via JNA work fine, just not this one.

I’ve tested the «trampoline DLL» method I mentioned above, and it solves the issue for me. The DLL is pretty simple, it is written in assembly using MINGW:

.globl _TrampolinePtr
.bss
.align 4
_TrampolinePtr:
.space 4
.text
.globl _TrampolineCall
.def _TrampolineCall; .scl 2; .type 32; .endef
_TrampolineCall:
movl (_TrampolinePtr), %eax
jmp *%eax
.globl _DllMain
.def _DllMain; .scl 2; .type 32; .endef
_DllMain:
pushl %ebp
movl %esp, %ebp
movl $1, %eax
popl %ebp
ret $12
.section .drectve
.ascii » -export:TrampolineCall»
.ascii » -export:TrampolinePtr,data»

Then I LoadLibraryW it, GetProcAddress on both TrampolinePtr and TrampolineCall, put the pointer to the JNA callback in TrampolinePtr, and pass the pointer to TrampolineCall to RegisterServiceCtrlHandlerExW.

I actually copy the DLL to a temporary location with a random name. Then I modify the DLL to change its name to that, and use Imagehlp to fixup the checksum. Finally MoveFileExW is used to schedule the DLL for deletion at next reboot

I made sure to compile the DLL without using MSVCRT at all, I set my «DllMain» function as the entry point in the linker. Trying to load via LoadLibraryW a DLL with dependencies was causing some DLL dependency dramas, since I didn’t need any dependencies I just got rid of the C runtime.

@twall

This might be a way for JNA to provide callbacks for other routines (like keyboard/mouse hooks) which require callbacks to reside in a DLL if you can figure out a decent method of making this reusable or configurable. You’d probably just have to «pre-allocate» a dozen or so static hooks to a pool for JNA to use and have it fail if they’ve all been used up; I don’t see how you could re-use any particular DLL address or write new ones to it. you’d then just embed these in the standard jnidispatch.dll to avoid additional issues writing/reading/disposing temporary files.

On Apr 2, 2012, at 1:30 AM, zackmartin wrote:

Hello twall, I believe it probably is specific to Windows7. I am going to test things on WinXP soon, I am guessing on WinXP none of this will be nexessary. As I mentioned, I determined it was error 126 in two ways:

  1. my declaration of RegisterServiceCtrlHandlerExW had «throw LastErrorException» on it, and that threw error 126
  2. I used rohitab API monitor (http://www.rohitab.com/apimonitor) and I saw that RegisterServiceCtrlHandlerExW was
    calling GetModuleHandleExW which was failing with 126
  3. I disassembled advapi32.dll, and by tracing things around I found that it does indeed end up calling GetModuleHandleExW for some reason

I am not sure WHY it would be calling GetModuleHandleExW

I know I’m not missing «jnidispatch.dll», etc., since other Win32 API calls via JNA work fine, just not this one.

I’ve tested the «trampoline DLL» method I mentioned above, and it solves the issue for me. The DLL is pretty simple, it is written in assembly using MINGW:

.globl _TrampolinePtr
.bss
.align 4
_TrampolinePtr:
.space 4
.text
.globl _TrampolineCall
.def _TrampolineCall; .scl 2; .type 32; .endef
_TrampolineCall:
movl (_TrampolinePtr), %eax
jmp *%eax
.globl _DllMain
.def _DllMain; .scl 2; .type 32; .endef
_DllMain:
pushl %ebp
movl %esp, %ebp
movl $1, %eax
popl %ebp
ret $12
.section .drectve
.ascii » -export:TrampolineCall»
.ascii » -export:TrampolinePtr,data»

Then I LoadLibraryW it, GetProcAddress on both TrampolinePtr and TrampolineCall, put the pointer to the JNA callback in TrampolinePtr, and pass the pointer to TrampolineCall to RegisterServiceCtrlHandlerExW.

I actually copy the DLL to a temporary location with a random name. Then I modify the DLL to change its name to that, and use Imagehlp to fixup the checksum. Finally MoveFileExW is used to schedule the DLL for deletion at next reboot

I made sure to compile the DLL without using MSVCRT at all, I set my «DllMain» function as the entry point in the linker. Trying to load via LoadLibraryW a DLL with dependencies was causing some DLL dependency dramas, since I didn’t need any dependencies I just got rid of the C runtime.


Reply to this email directly or view it on GitHub:
#62 (comment)

@twall

Here’s the native junk required for the DLL-embedded jumps; it establishes four «trampolines» which would be returned in place of the heap-allocated callback trampolines. MASM is required on win64/MSVC (yuck):

static void (*fn[4])();

extern void asmfn0(int,char**);
extern void asmfn1(int,char**);
extern void asmfn2(int,char**);
extern void asmfn3(int,char**);

#if defined(__x86_64__)
#ifdef _MSC_VER
/* No amd64 support for inline asm */
#else
#define ASMFN(X) asm(".globl _asmfn" #X "n                                    
_asmfn" #X ":n                                                                
 jmp *(8*" #X ")+_fn(%rip)")
#endif
#else /* __x86_64 */
#ifdef _MSC_VER
#define ASMFN(X) 
__asm asmfn ## X PROC NEAR 
__asm jmp fn[X]
#else
#define ASMFN(X) asm(".globl _asmfn" #X "n                                    
_asmfn" #X ":n                                                                
 jmp *(_fn+4*" #X ")")
#endif
#endif /* __x86_64 */

ASMFN(0);
ASMFN(1);
ASMFN(2);
ASMFN(3);

@twall

Added branch dll-callbacks. Working functionality, pending build fixes to work properly with MS tools in addition to mingw64.

@twall

Please re-test against dll-callbacks branch @zackmartin

I’m running maven build with command —

mvn clean install -DdestFolder=<destination-folder-path>

but it fails with following error —

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (Transpilation) on project UI: Command execution failed.: Process exited with an error: 126 (Exit value: 126) -> [Help 1]

I’m unable to get cause of 126 error code. Could you please help to understand the cause?

asked Mar 1, 2021 at 7:28

Alpha's user avatar

Load 7 more related questions

Show fewer related questions

Понравилась статья? Поделить с друзьями:

Не пропустите эти материалы по теме:

  • Яндекс еда ошибка привязки карты
  • Джава ошибка 112
  • Дефект ошибка инцидент
  • Джава виртуал машин лаунчер ошибка виндовс 10
  • Дефект ecu b1342 ошибка форд фокус 2

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии