Windows Vista的:无法加载DLL“x.dll”:无效的内存位置访问。 (DllNotFoundException) [英] Windows Vista: Unable to load DLL 'x.dll': Invalid access to memory location. (DllNotFoundException)

查看:210
本文介绍了Windows Vista的:无法加载DLL“x.dll”:无效的内存位置访问。 (DllNotFoundException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天下午有Windows Vista中(他回家,但我正在测试一个商业版具有相同的结果)。

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

我们使用一个.DLL,获取计算机的硬件ID的。它的用法很简单,示例程序我已经创作的作品。该DLL 这从AzSdk 。 事实上,这个工程完全在Windows XP下。然而,对于一些奇怪的原因,我们的项目(路大)里面,我们得到这个异​​常:

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

我不知道有什么可以引起问题,因为我有完全的控制权的文件夹。该项目是AC#.NET Windows窗体应用程序,一切工作正常,除了呼吁外部库。

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.

我声明这是这样的:。(注:这是的没有的一个COM库,它并不需要注册)

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);

然后调用code是相当简单:

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

当你创建一个示例应用程序,它的工作原理,但我projectit里面没有。在XP下正常工作。任何什么想法我应该做的在Vista中,使这项工作? 正如我所说的,该文件夹及其子文件夹有大家完全控制。

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".

在此先感谢,

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

UPDATE: I do not have Vista SP 1 installed.

更新2:我已经安装了Vista SP1和现在,随着UAC禁用,甚至连简单的示例工程! :(该死的Vista操作系统。

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

推荐答案

@ <一href="http://stackoverflow.com/questions/29284/windows-vista-unable-to-load-dll-xdll-invalid-access-to-memory-location-dllnotf#29400"相对=nofollow>马丁

你没有得到UAC提示的原因是因为UAC的只能改变过程有多开始,一旦进程正在运行,它必须保持在同一高度的水平。在UAC提示会发生,如果:

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中认为它是一个安装程序(大量的规则在这里 ,最简单的是,如果这就是所谓的setup.exe),
  • 如果它标记为以管理员身份运行(你可以通过更改快捷方式或exe文件的属性编辑此),或
  • 如果exe文件中包含一个清单,要求管理员权限。
  • 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.

前两个选项的解决方法'传统'应用程序是围绕UAC之前,做了新的应用正确的方法是的嵌入清单资源的要求,你需要的特权。

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.

一些程序,如的Process Explorer 出现提升正在运行的流程(当你选择显示详细信息所有的过程,在文件菜单在这种情况下),但他们真正做的是开始一个新的实例,那就是被提升的新实例 - 而不是最初运行的一个。这样做,如果你的应用程序只有一些部分需要抬高(例如,一个特殊的管理选项对话框)这是建议的方式。

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

这篇关于Windows Vista的:无法加载DLL“x.dll”:无效的内存位置访问。 (DllNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆