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

6

4

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.

Copper answered 27/8, 2008 at 1:3 Comment(0)
D
2

@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).

Dibs answered 27/8, 2008 at 9:30 Comment(0)
K
4

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.

Khedive answered 27/8, 2008 at 8:51 Comment(1)
+1 for explaining the problem in such a way that I can understand what the real problem is, and know what to start looking forRoane
D
2

@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).

Dibs answered 27/8, 2008 at 9:30 Comment(0)
M
1

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.

Marrakech answered 27/8, 2008 at 1:24 Comment(0)
H
0

Have you made a support request to the vendor? Perhaps there's something about the MacBook Pro hardware that prevents the product from working.

Husted answered 27/8, 2008 at 2:19 Comment(0)
B
0

Given that the exception is a DllNotFoundException, you might want to try checking the HardwareID.dll with Dependency Walker BEFORE installing any dev tools on the Vista install to see if there is in fact a dependency missing.

Bernita answered 27/8, 2008 at 2:21 Comment(1)
The name of the exception might be missleading. See post above.Mysia
B
0

In addition to allowing full control to "Everyone" does the location also allow processes with a medium integrity level to write?

How do I check that ? I am new to Vista, I don't like it too much, it's too slow inside a VM for daily work and for VStudio usage inside a Virtual Machine, it doesn't bring anything new.

From a command prompt to you can execute:

icacls C:\Folder

If you see a line such as "Mandatory Label\High Mandatory Level" then the folder is only accessible to a high integrity process. If there is no such line then medium integrity processes can access it provided there are no other ACLs denying access (based on user for example).

EDIT: Forgot to mention you can use the /setintegritylevel switch to actually change the required integrity level for accessing the object.

Bernita answered 27/8, 2008 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.