473,614 Members | 2,609 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 11011
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
28066
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
43191
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 used: ‘TCP/IP'. Communication API being used: ‘SOCKETS'. Location where the error was detected:...
3
7028
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 be effective until the directory cache is refreshed. 2. database catalog was OK:
32
5927
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
2503
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: A call to PInvoke function 'tempModule!<Module>::AddTwoDoubles2' has unbalanced the stack. This is...
0
1345
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
3636
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. I did notice the MySql lib appears to be ver 4.nn of MySql's tree, but still the functions appear...
1
3090
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 hwnd, long dwObjectID, long dwChildID, out IAccessible iAccessible, out object pvarChild); Defination:
2
2653
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 the PInvoke signature match the target unmanaged signature.
2
1877
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 = 0x0004; // pszSound points to a
0
8142
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7115
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5549
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
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
1438
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.