Windows Vista:无法加载 DLL“x.dll”:对内存位置的访问无效。 (DllNotFound异常)

发布于 2024-07-05 18:28:37 字数 1453 浏览 6 评论 0原文

今天下午我在客户的机器上进行了测试,该机器装有 Windows Vista(他在家,但我在商业版上进行测试,结果相同)。

我们使用 .DLL 来获取计算机的硬件 ID。 它的用法非常简单,我创建的示例程序也可以工作。 该 Dll 是 来自 AzSdk。 事实上,这在 Windows XP 下完美运行。 然而,由于一些奇怪的原因,在我们的项目(更大)中,我们得到了这个异常:

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

我不知道是什么导致了问题,因为我完全控制了该文件夹。 该项目是 ac#.net Windows 窗体应用程序,除了对外部库的调用之外,一切正常。

我这样声明它:(注意:它不是 COM 库,并且不需要注册)。

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

然后调用代码非常简单:

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*");
}

当您创建示例应用程序时,它可以工作,但在我的项目中却不能。 XP下工作正常。 关于我应该在 Vista 中做什么才能使其工作有什么想法吗? 正如我所说,该文件夹及其子文件夹对“所有人”具有完全控制权。

更新:我没有安装 Vista SP 1。

更新2:我已经安装了Vista SP1,现在,在禁用UAC的情况下,甚至连简单的示例都不起作用! :( 该死的维斯塔。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

或十年 2024-07-12 18:28:37

无法加载 DLL“HardwareID.dll”:
对内存位置的访问无效。
(HRESULT 异常:0x800703E6)

DllNotFoundException 的名称让您感到困惑 - 这不是查找或加载 DLL 文件的问题,问题是加载 DLL 时,它会执行非法内存访问,从而导致加载过程失败。

就像这里的另一张海报一样,我认为这是一个 DEP 问题,并且您的 UAC 等更改最终允许您为此应用程序禁用 DEP。

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.

往日情怀 2024-07-12 18:28:37

@马丁

您没有收到 UAC 提示的原因是 UAC 只能更改进程启动的方式,一旦进程运行,它必须保持在相同的高度级别。 如果出现以下情况,则会出现 UAC 提示:

  • Vista 认为它是一个安装程序(很多此处的规则,最简单的一个是它是否名为“setup.exe”),
  • 如果它被标记为“以管理员身份运行”(您可以通过更改快捷方式或 exe 的属性来编辑它),或者
  • 如果exe 包含一个请求管理员权限的清单。

前两个选项是 UAC 之前的“旧”应用程序的解决方法,对于新应用程序执行此操作的正确方法是 嵌入清单资源,请求您需要的权限。

某些程序(例如Process Explorer)似乎会提升正在运行的进程(在这种情况下,当您在文件菜单中选择“显示所有进程的详细信息”时),但他们真正做的是启动一个新实例,并且是该新实例被提升 - 而不是最初运行的实例。 如果只有应用程序的某些部分需要提升(例如特殊的“管理选项”对话框),这是推荐的方法。

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

数理化全能战士 2024-07-12 18:28:37

您部署代码的机器是64位机器吗? 您还可能遇到 DEP 问题。

编辑

这是配备第一代 Core Duo 2 Intel 处理器的第一代 Macbook Pro。 远非 64 位。

我提到了 64 位,因为在低级别,从 32 位到 64 位的结构无法得到正确处理。 由于计算机不是 64 位,因此下一步很可能禁用 DEP。 Vista 确实比 XP SP2 更安全。

好吧,我刚刚全局关闭了 DEP,但没有效果。 同样的错误。

嗯,我还了解到人们在将计算机更新到 Vista SP1 后遇到此错误。 这些 Vista 安装有 SP1 吗?

结果是完全不同的东西。 只是为了测试,我禁用了 UAC(注意:我没有收到任何提示)。

太好了,我本来想建议的,但我想你可能已经尝试过了。

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.

孤寂小茶 2024-07-12 18:28:37

您是否向供应商提出过支持请求? 也许 MacBook Pro 硬件存在某些问题,导致该产品无法正常工作。

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

冷…雨湿花 2024-07-12 18:28:37

鉴于异常是 DllNotFoundException,您可能需要在安装之前尝试使用 Dependency Walker 检查 HardwareID.dll Vista 安装上的任何开发工具都可以查看是否确实缺少依赖项。

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.

爱的那么颓废 2024-07-12 18:28:37

<块引用>

除了允许“每个人”完全控制之外,该位置还允许中等完整性级别的进程进行写入吗?

我该如何检查? 我是 Vista 的新手,不太喜欢它,它在虚拟机内对于日常工作来说太慢了,对于在虚拟机内使用 VStudio 来说,它没有带来任何新东西。

从命令提示符到您可以执行:

icacls C:\Folder

如果您看到诸如“Mandatory Label\High Mandatory Level”之类的行,则该文件夹只能由高完整性进程访问。 如果没有这样的行,那么只要没有其他 ACL 拒绝访问(例如基于用户),中等完整性进程就可以访问它。

编辑:忘记提及您可以使用 /setintegritylevel 开关来实际更改访问对象所需的完整性级别。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文