Windows Vista: Unable to load DLL 'x.dll': Invalid access to memory location. (DllNotFoundException)

11,904

Solution 1

@Martín

The reason you were not getting the UAC prompt is because UAC can only change how a process is started, once the process is running it must stay at the same elevation level. The UAC will prompt will happen if:

  • Vista thinks it's an installer (lots of rules here, the simplest one is if it's called "setup.exe"),
  • If it's flagged as "Run as Administrator" (you can edit this by changing the properties of the shortcut or the exe), or
  • If the exe contains a manifest requesting admin privileges.

The first two options are workarounds for 'legacy' applications that were around before UAC, the correct way to do it for new applications is to embed a manifest resource asking for the privileges that you need.

Some program, such as Process Explorer appear to elevate a running process (when you choose "Show details for all process" in the file menu in this case) but what they really do is start a new instance, and it's that new instance that gets elevated - not the one that was originally running. This is the recommend way of doing it if only some parts of your application need elevation (e.g. a special 'admin options' dialog).

Solution 2

Unable to load DLL 'HardwareID.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)

The name of DllNotFoundException is confusing you - this isn't a problem with finding or loading the DLL file, the problem is that when the DLL is loaded, it does an illegal memory access which causes the loading process to fail.

Like another poster here, I think this is a DEP problem, and that your UAC, etc, changes have finally allowed you to disable DEP for this application.

Solution 3

Is the machine you have the code deployed on a 64-bit machine? You could also be running into a DEP issue.

Edit

This is a 1st gen Macbook Pro with a 1st gen Core Duo 2 Intel processor. Far from 64 bits.

I mentioned 64 bit, because at low levels structs from 32 bit to 64 bit do not get properly handled. Since the machines aren't 64bit, then more than likely disabling DEP would be a good logical next step. Vista did get more secure than XP SP2.

Well, I've just turned DEP globally off to no avail. Same error.

Well, I also read that people were getting this error after updating a machine to Vista SP1. Do these Vista installs have SP1 on them?

Turns out to be something completely different. Just for the sake of testing, I've disabled de UAC (note: I was not getting any prompt).

Great, I was actually going to suggest that, but I figured you probably tried it already.

Share:
11,904

Related videos on Youtube

Martin Marconcini
Author by

Martin Marconcini

Android developer (Kotlin/Java) and some Flutter (newbie). Did iOS (Swift) for a while, not really up to date with the latest Swift. I'm very interested in doing Rust, but I haven't found a chance to properly learn it and nobody will pay me to do it so... here we are :) I haven't done Objective-C since before ARC. I haven't done C#.NET since .NET 3.5 in 2011. I occasionally use Windows for gaming. I mainly use Linux for everything else (and macOS when I have no choice, which is sometimes the case in some corporate environments). Note to Recruiters: Please don't make me offers that are not 100% remote friendly; I've been working from home since 2001 and I expect to continue to do so, pandemic or not. Coming to an office every now and then or once a week is fine, but it should not be the norm; as a developer, the distractions are too many. I disagree with StackOverflow discontinuing JOBS/Developer Story, so I may not be as active as before on this site.

Updated on April 19, 2022

Comments

  • Martin Marconcini
    Martin Marconcini over 1 year

    I was testing on a customer's box this afternoon which has Windows Vista (He had home, but I am testing on a Business Edition with same results).

    We make use of a .DLL that gets the Hardware ID of the computer. It's usage is very simple and the sample program I have created works. The Dll is This from AzSdk. In fact, this works perfectly under Windows XP. However, for some strange reason, inside our project (way bigger), we get this exception:

    Exception Type:        System.DllNotFoundException
    Exception Message:     Unable to load DLL 'HardwareID.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)
    Exception Target Site: GetHardwareID
    

    I don't know what can be causing the problem, since I have full control over the folder. The project is a c#.net Windows Forms application and everything works fine, except the call for the external library.

    I am declaring it like this: (note: it's not a COM library and it doesn't need to be registered).

    [DllImport("HardwareID.dll")]
    public static extern String GetHardwareID(bool HDD,
       bool NIC, bool CPU, bool BIOS, string sRegistrationCode);
    

    And then the calling code is quite simple:

    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Text = GetHardwareID(cb_HDD.Checked, 
                                      cb_NIC.Checked, 
                                      cb_CPU.Checked, 
                                      cb_BIOS.Checked, 
                                     "*Registration Code*");
    }
    

    When you create a sample application, it works, but inside my projectit doesn't. Under XP works fine. Any ideas about what should I do in Vista to make this work? As I've said, the folder and its sub-folders have Full Control for "Everybody".

    UPDATE: I do not have Vista SP 1 installed.

    UPDATE 2: I have installed Vista SP1 and now, with UAC disabled, not even the simple sample works!!! :( Damn Vista.

  • Rachel
    Rachel about 12 years
    +1 for explaining the problem in such a way that I can understand what the real problem is, and know what to start looking for
  • Pupsik
    Pupsik about 6 years
    The name of the exception might be missleading. See post above.