Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendNotifyMessage and PostMessage

Status
Not open for further replies.

Crazy321

Programmer
Joined
Oct 15, 2003
Messages
7
Location
BE
Hi,

I need some help with PostMessage or SendNotifyMessage.

In the past I was using SendMessage, but because this waits untill it is processed by the target application it was not what I wanted.

Now I want to change the way I send/post it.

I've read that both PostMessage and SendNotifyMessage do not wait.

Here is a part of the code i'm using to test/get it working with SendNotifyMessage


Code:
public class TestSendMessage {
        [DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        private static extern Boolean SendNotifyMessage(IntPtr hWnd, WndMsg Msg, IntPtr wParam, IntPtr lParam);

        public static void sendTo() {
            IntPtr objHandle = FindWindow(null, "testform")
            if (!objHandle.Equals(IntPtr.Zero)) {
                 bool blnOK = SendNotifyMessage(objHandle, WndMsg.WM_COPYDATA, IntPtr.Zero, IntPtr.Zero);
               if (!blnOK) {
                    int intErrorCode = Marshal.GetLastWin32Error();
                } 
            }
	}
}

And in the main of my app i do:
Code:
            while (true) {
		TestSendMessage.sendTo(); 
                System.Threading.Thread.Sleep(2000);
            }

The error i get in "GetLastWin32Error is 1159, so ERROR_MESSAGE_SYNC_ONLY.

Am I using it wrong? and what can I do to fix it?


Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top