473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

PInvokeStackImbalance was detected.

The MDA appears on the call to OpenDesktop.

I have tried a variety of approaches (including specifying the A and W
variant with ExactSpelling=true, and PreserveSig=true) but none of them seem
to work. This code was copied from a 1.1 sample that purported to work
without an error.
public static class Desktop
{
private const long DESKTOP_SWITCHDESKTOP = 0x0100L;

[DllImport("user32.dll", CharSet=CharSet.Auto, PreserveSig=true)]
private static extern IntPtr OpenDesktop(string lpszDesktop, int
dwFlags, bool fInherit, long dwDesiredAccess);

[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);

public static bool IsLocked()
{
IntPtr hdt = OpenDesktop("Default", 0, false,
DESKTOP_SWITCHDESKTOP);

if (IntPtr.Zero == hdt)
return false;

return SwitchDesktop(hdt);
}
}

Jan 26 '06 #1
4 10991
John,
[DllImport("user32.dll", CharSet=CharSet.Auto, PreserveSig=true)]
private static extern IntPtr OpenDesktop(string lpszDesktop, int
dwFlags, bool fInherit, long dwDesiredAccess);

^^^^

Should be a (u)int.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 26 '06 #2

"John Sudds" <John Su***@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
| The MDA appears on the call to OpenDesktop.
|
| I have tried a variety of approaches (including specifying the A and W
| variant with ExactSpelling=true, and PreserveSig=true) but none of them
seem
| to work. This code was copied from a 1.1 sample that purported to work
| without an error.
|
|
| public static class Desktop
| {
| private const long DESKTOP_SWITCHDESKTOP = 0x0100L;
|
| [DllImport("user32.dll", CharSet=CharSet.Auto, PreserveSig=true)]
| private static extern IntPtr OpenDesktop(string lpszDesktop, int
| dwFlags, bool fInherit, long dwDesiredAccess);
|
| [DllImport("user32.dll")]
| private static extern bool SwitchDesktop(IntPtr hDesktop);
|
| public static bool IsLocked()
| {
| IntPtr hdt = OpenDesktop("Default", 0, false,
| DESKTOP_SWITCHDESKTOP);
|
| if (IntPtr.Zero == hdt)
| return false;
|
| return SwitchDesktop(hdt);
| }
| }
|

The last argument is not a long it should be an unsigned int.
The MDA did not exist in v1.1, so that means it's only reported now.

Willy.


Jan 26 '06 #3

THANKS to both of you! My problem was that ACCESS_MASK (the last param of
OpenDesktop) is unsigned.
"John Sudds" wrote:
The MDA appears on the call to OpenDesktop.

I have tried a variety of approaches (including specifying the A and W
variant with ExactSpelling=true, and PreserveSig=true) but none of them seem
to work. This code was copied from a 1.1 sample that purported to work
without an error.
public static class Desktop
{
private const long DESKTOP_SWITCHDESKTOP = 0x0100L;

[DllImport("user32.dll", CharSet=CharSet.Auto, PreserveSig=true)]
private static extern IntPtr OpenDesktop(string lpszDesktop, int
dwFlags, bool fInherit, long dwDesiredAccess);

[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);

public static bool IsLocked()
{
IntPtr hdt = OpenDesktop("Default", 0, false,
DESKTOP_SWITCHDESKTOP);

if (IntPtr.Zero == hdt)
return false;

return SwitchDesktop(hdt);
}
}

Jan 26 '06 #4
For those who are interested in the final rewrite, here it is. This code is
running inside a screen saver, and accurately detects whether the Default
desktop has been locked (before, after, or during).

public static class Desktop
{
private const uint DESKTOP_READOBJECTS = 0x0001;
private const uint DESKTOP_WRITEOBJECTS = 0x0080;
private const uint DESKTOP_SWITCHDESKTOP = 0x0100;
private const uint AccessUnlocked = DESKTOP_READOBJECTS |
DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP;

[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
private static extern IntPtr OpenDesktop(string lpszDesktop, int
dwFlags,
bool fInherit, uint dwDesiredAccess);

[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);

public static bool IsNotLocked()
{
IntPtr hdt = OpenDesktop("Default", 0, false, AccessUnlocked);

// If we can make the switch, the desktop is not locked
if (SwitchDesktop(hdt))
return true;

return false;
}
}

Jan 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chandika | last post by:
Hi all, One of my database was suspected, So I try to recover database then it gives this error Err. 823 Torn Page Detected 823, ... 24, spid51 i/o error Torn Page (Detected) during read...
3
by: Tim Reynolds | last post by:
I support a .Net application running on a SERVER accessing MF Db2 data. Occasionally, we have some type of connection problem that we have been unable to debug up to this point. We typically...
3
by: Laura | last post by:
I've just installed the DB2 Run-time client in a Solaris machine. Then I finnish the installation configuring the connection: 1. machine catalog was OK: ========================== $ db2 catalog...
32
by: Clunixchit | last post by:
How can i read lines of a file and place each line read in an array? for exemple; array=line1 array=line2 ...
2
by: Marek | last post by:
Hi I'm trying to call a native C++ dll using the following code (both C# and C++ code segments included). When I make the call to the method (AddTwoDoubles) that has no return value all is fine. ...
0
by: MJKulangara | last post by:
I have an ap written in vb.net using 1.2 framework that makes a call to a c++ dll. The executable I create runs just fine, but when I run the ap in debug mode I get a PInvokeStackImbalance error....
1
by: urbansound | last post by:
Hi, I'm having trouble tracking down a PInvoke error in the MySqlDriverCS lib, which is detected even in the author's samples converted to VS v8 .Net 2.0. The calling maze is provided, but the...
1
by: raghavendra2007 | last post by:
Hi, I am trying to develop the ScreenReader in C#, I need to use IAccessibility to access the system events. Before that I should require to get the IAccesibility object using...
2
by: John M. Gamble | last post by:
I'm getting this message in Visual Studio 2005: PInvokeStackImbalance was detected Message: A call to PInvoke function 'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack. ...
2
by: linuxfedora | last post by:
I wrote a class for playing wav file, the code: class SoundPlayer { // flag values for SoundFlags argument on PlaySound public int SND_SYNC = 0x0000; // play synchronously (default) public...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.