Solved

C# calling unmanaged DLL failed under Windows 7, but successfully under XP

Posted on 2011-09-23
5
799 Views
Last Modified: 2013-12-17
I have an unmanaged 32bit DLL, which uses callback function.

When using unmanaged codes, such as Visual C++, Delphi, Visual Basic, all of them can call the DLL successfully under both Windows XP(SP3) and Windows 7(32bit and 64bit). I have made many tests without any problems.

When using C# to call the DLL under Windows XP(SP3), everything is still OK.

However, when using C# to call the DLL under Windows 7(32bit), I will always get the error message as follows:

 Error messagebox
After some time, the messagebox will ask me whether to debug or not, if I choose to debug, then Visual Studio 2008 will be loaded, as follows:

 VS 2008 Debug Interface
Then if I select the "Break" button, I will get into disassembled codes, as follows:

 VS 2008 Disassembly Codes
The C# program is built for .NET framework 3.5, and I have confirmed that .NET framework 3.5 has been installed on the system.

Can anyone tell me what is the problem? Thanks
0
Comment
Question by:chcw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:Didier Vally
ID: 36586226
Have you tried to change the .net framework version in your c# project ?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 167 total points
ID: 36586313
Part of the error message - priviliged instruction - I must admit this is something I don't recall ever seeing.  A quick web search gave the following link:
http://stackoverflow.com/questions/89607/what-is-a-privileged-instruction/89716

Which says that it is something that needs to be executed in ring 0 (usually your app would run in ring 3).
It could be something being stopped by the UAC of Win 7 - have you tried to run the app with administrator priviliges?  It could be a bug, but try running with elevated priviliges first - much simpler to try and maybe it then runs correctly.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 166 total points
ID: 36587701
Usually, the framework prevents you from calling privileged instructions from standard C# code.

But C# has a feature that enables you to use pointers, and then you fall out of that prevention zone.

Do you see the work unsafe somewhere in the code, either in front of a declaration, or in a structure such as the following?

unsafe
{
    // code with pointers.
}

If so, that might be the cause of your problem, and there is no solution. Windows XP will let go some operations with pointers that Windows 7, with its higher security, will not let pass. No matter is you are administator or not, you are limited in what you can do with pointers.
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 167 total points
ID: 36598388
Can you post the (un-managed) callback definition and API that registers the function address and your C# implementation along with documentation for the DLL?
0
 
LVL 8

Author Closing Comment

by:chcw
ID: 36618912
Thanks to all of you. I have solved the problem by myself. Acutally the problem is not caused by the DLL or the C# program. Instead, as I use a third-party tool to protect the DLL, which cause the problem. Now I have upgraded the third-party tool to a new version to solve the problem.
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question