WaitForSingleObject don't work with FindWindow

  • Thread starter Thread starter HervéP
  • Start date Start date
H

HervéP

Hi,
I tried to do a software on my PocketPC, that wait an another software to
exit.
I invoke "WaitForSingleObject" and FindWindowW :
[DllImport("coredll.dll", EntryPoint="WaitForSingleObject", SetLastError =
true)]
private static extern int WaitForSingleObject(IntPtr hHandle, uint
dwMilliseconds);

[DllImport("coredll.dll", EntryPoint="FindWindowW", SetLastError=true)]
private static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

Call to these functions (in my Form) :

IntPtr handle1 = FindWindowCE(null, "FormTest");
MessageBox.Show("Handle : "+handle1+" Wait return :
"+WaitForSingleObjectCE(handle1,50000).ToString());

But the result is always :

- when the application "FormTest" isn't running :
"Handle : 0 Wait return : -1" (this is normal)

- when the application "FormTest" is running :
"Handle : 2681648 Wait return : -1" (that don't work : the function
WaitForSingleObjectCE return immediately with "-1")

What's wrong ?

And... I also tried with OpenNETCF, but I'm wrong with the ProcessEntry and
with the Wait : that seems to work once, but not after, and after that's
ok... that's strange !

Thanks in advance !

Hervé
 
Thanks Chris.
ok... I need a process handle.
So :
- Is it possible to fin the process handle with a Window handle ? If so,
how ?
- In using GetProcesses in OpenNETCF, there is a bug : sometimes I can't
get the Handle because OverflowException. The process ID is (in example)
2,465,055,034 and it is to big to convert to IntPtr. What about the bug ?

Thanks for helping me !

Hervé

You can't wait on a Window handle. You need a process handle.

-Chris

HervéP said:
Hi,
I tried to do a software on my PocketPC, that wait an another software to
exit.
I invoke "WaitForSingleObject" and FindWindowW :
[DllImport("coredll.dll", EntryPoint="WaitForSingleObject", SetLastError
= true)]
private static extern int WaitForSingleObject(IntPtr hHandle, uint
dwMilliseconds);

[DllImport("coredll.dll", EntryPoint="FindWindowW", SetLastError=true)]
private static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

Call to these functions (in my Form) :

IntPtr handle1 = FindWindowCE(null, "FormTest");
MessageBox.Show("Handle : "+handle1+" Wait return :
"+WaitForSingleObjectCE(handle1,50000).ToString());

But the result is always :

- when the application "FormTest" isn't running :
"Handle : 0 Wait return : -1" (this is normal)

- when the application "FormTest" is running :
"Handle : 2681648 Wait return : -1" (that don't work : the function
WaitForSingleObjectCE return immediately with "-1")

What's wrong ?

And... I also tried with OpenNETCF, but I'm wrong with the ProcessEntry
and with the Wait : that seems to work once, but not after, and after
that's ok... that's strange !

Thanks in advance !

Hervé
 
I think I have found the bug in OpenNETCF (for the 32 bits PDA).
It was just a cast (to Int32) to add in the Handle property of the
ProcessEntry class.

public IntPtr Handle
{
get { return (IntPtr)((Int32)m_pe.ProcessID); }
}


Hervé
 
Well, I'm not sure if it's really the 'right' thing to do, but currently in
Windows CE the process ID and the process handle have the same values.

Paul T.
 
Not sure what you're looking at. The source in Vault is as I originally
wrote it:

/// <summary>
/// Identifier of the process. The contents of this member can be used by
Win32 API elements.
/// </summary>
[CLSCompliant(false)]
public uint ProcessID
{
get { return (uint)m_pe.ProcessID; }
}


--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
Back
Top