473,549 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PInvokeStackImb alance 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=t rue, and PreserveSig=tru e) 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_SWITCHD ESKTOP = 0x0100L;

[DllImport("user 32.dll", CharSet=CharSet .Auto, PreserveSig=tru e)]
private static extern IntPtr OpenDesktop(str ing lpszDesktop, int
dwFlags, bool fInherit, long dwDesiredAccess );

[DllImport("user 32.dll")]
private static extern bool SwitchDesktop(I ntPtr hDesktop);

public static bool IsLocked()
{
IntPtr hdt = OpenDesktop("De fault", 0, false,
DESKTOP_SWITCHD ESKTOP);

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

return SwitchDesktop(h dt);
}
}

Jan 26 '06 #1
4 11005
John,
[DllImport("user 32.dll", CharSet=CharSet .Auto, PreserveSig=tru e)]
private static extern IntPtr OpenDesktop(str ing 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***@discussio ns.microsoft.co m> wrote in message
news:98******** *************** ***********@mic rosoft.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=t rue, and PreserveSig=tru e) 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_SWITCHD ESKTOP = 0x0100L;
|
| [DllImport("user 32.dll", CharSet=CharSet .Auto, PreserveSig=tru e)]
| private static extern IntPtr OpenDesktop(str ing lpszDesktop, int
| dwFlags, bool fInherit, long dwDesiredAccess );
|
| [DllImport("user 32.dll")]
| private static extern bool SwitchDesktop(I ntPtr hDesktop);
|
| public static bool IsLocked()
| {
| IntPtr hdt = OpenDesktop("De fault", 0, false,
| DESKTOP_SWITCHD ESKTOP);
|
| if (IntPtr.Zero == hdt)
| return false;
|
| return SwitchDesktop(h dt);
| }
| }
|

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=t rue, and PreserveSig=tru e) 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_SWITCHD ESKTOP = 0x0100L;

[DllImport("user 32.dll", CharSet=CharSet .Auto, PreserveSig=tru e)]
private static extern IntPtr OpenDesktop(str ing lpszDesktop, int
dwFlags, bool fInherit, long dwDesiredAccess );

[DllImport("user 32.dll")]
private static extern bool SwitchDesktop(I ntPtr hDesktop);

public static bool IsLocked()
{
IntPtr hdt = OpenDesktop("De fault", 0, false,
DESKTOP_SWITCHD ESKTOP);

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

return SwitchDesktop(h dt);
}
}

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_READOBJ ECTS = 0x0001;
private const uint DESKTOP_WRITEOB JECTS = 0x0080;
private const uint DESKTOP_SWITCHD ESKTOP = 0x0100;
private const uint AccessUnlocked = DESKTOP_READOBJ ECTS |
DESKTOP_WRITEOB JECTS | DESKTOP_SWITCHD ESKTOP;

[DllImport("user 32.dll", CharSet=CharSet .Auto, SetLastError=tr ue)]
private static extern IntPtr OpenDesktop(str ing lpszDesktop, int
dwFlags,
bool fInherit, uint dwDesiredAccess );

[DllImport("user 32.dll")]
private static extern bool SwitchDesktop(I ntPtr hDesktop);

public static bool IsNotLocked()
{
IntPtr hdt = OpenDesktop("De fault", 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
28060
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 at offset 0x0000000040e0000 in file .........
3
43169
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 receive one of these IBM.Data.DB2.DB2Exception messages: ERROR SQL30081N A communication error has been detected. Communication protocol being...
3
7025
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 tcpip node atlas remote dsroracle server 8100 DB20000I The CATALOG TCPIP NODE command completed successfully. DB21056W Directory changes may not...
32
5908
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
2502
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. When I try and call a function that returns a double (AddTwoDoubles2) I get the following message: PInvokeStackImbalance was detected Message:...
0
1337
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. Any suggestions? TIA, MKulangara
1
3631
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 bottom two are really the (offending) and external unsafe (offended), being called. I just cannot see where it's off track to cause the error. ...
1
3081
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 AccessibleObjectFromEvent. The signature and the defination shown below. Signature: public static extern uint AccessibleObjectFromEvent(IntPtr...
2
2648
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. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of...
2
1875
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 int SND_ASYNC = 0x0001; // play asynchronously public int SND_NODEFAULT = 0x0002; // silence (!default) if sound not found public int SND_MEMORY =...
0
7464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7826
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6065
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.