Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...