Solved

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

Posted on 2011-09-23
5
795 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
Comment Utility
Have you tried to change the .net framework version in your c# project ?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now