?
Solved

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

Posted on 2011-09-23
5
Medium Priority
?
810 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
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 45

Accepted Solution

by:
AndyAinscow earned 501 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 498 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 501 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

807 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